Skip to content

Commit

Permalink
through BS, Arrow key, when no text
Browse files Browse the repository at this point in the history
  • Loading branch information
ishikawakouji committed Dec 5, 2023
1 parent e0d5271 commit 8cfda6b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
1 change: 1 addition & 0 deletions PushToWSLg/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 51 additions & 22 deletions PushToWSLg/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,37 @@ public struct POINT
static extern bool GetCursorPos(out POINT lpPoint);

// カーソル位置にクリップボードのテキストを挿入
private async void InsertClipboardTextAtCursor(string text)
private void InsertClipboardTextAtCursor(string text)
{
POINT cursorPos;


Clipboard.SetText(text);
//Clipboard.SetDataObject(text, false);

SendKeyEventToAnotherWindow("^v");


}

// send key event
private async void SendKeyEventToAnotherWindow(string etext)
{
POINT cursorPos;
this.Hide();

await Task.Delay(200);

if (GetCursorPos(out cursorPos))
{
// カーソル位置にクリップボードのテキストを挿入
SendKeys.SendWait("^v");
SendKeys.SendWait(etext);
}

this.Show();
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
/*
int textlen = textBox1.Text.Length;
string text = "";
bool flagpaste = true;
Expand All @@ -130,22 +138,6 @@ private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

switch (e.KeyChar)
{
case (char)Keys.Left:
case (char)Keys.Right:
case (char)Keys.Back:
if (textlen == 0)
{
text += e.KeyChar;
}
else
{
flagpaste = false;
}
break;
case (char)Keys.Up:
case (char)Keys.Down:
text += e.KeyChar;
break;
case (char)Keys.Enter:
text = textBox1.Text;
textBox1.Clear();
Expand All @@ -164,9 +156,8 @@ private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
InsertClipboardTextAtCursor(text);
}
*/


/*
if (e.KeyChar == (char)Keys.Enter)
{
string text = textBox1.Text;
Expand All @@ -182,8 +173,46 @@ private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
e.Handled = true;
}
*/

}

private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
int textlen = textBox1.Text.Length;
string etext = "";

// enter, arrow, backspace
if (textlen == 0)
{
switch (e.KeyCode)
{
case Keys.Up:
etext = "{UP}";
break;
case Keys.Down:
etext = "{DOWN}";
break;
case Keys.Left:
etext = "{LEFT}";
break;
case Keys.Right:
etext = "{RIGHT}";
break;
case Keys.Back:
etext = "{BS}";
break;
default:
break;
}
if (etext.Length != 0)
{
SendKeyEventToAnotherWindow(etext);
}

}

}

}
}

0 comments on commit 8cfda6b

Please sign in to comment.