質問するログイン新規登録

回答編集履歴

1

見直しキャンペーン中

2023/07/22 10:15

投稿

TN8001
TN8001

スコア10210

answer CHANGED
@@ -1,52 +1,52 @@
1
- `RawInput`とか`WH_KEYBOARD_LL`とかがキーワードになりますが、難しいので出来合いのものを使わせてもらいましょう。
2
-
3
- [NuGet Gallery | KeyboardHookManager 1.1.0](https://www.nuget.org/packages/KeyboardHookManager/1.1.0)
4
- 例えばこれだとこんな感じでしょうか。
5
- 注意)こちらを薦めているわけではありません。ソースコード・ライセンス表記があって、そこそこDL数もあり新しいものだったってだけです。
6
-
7
- ```C#
8
- // [NuGet Gallery | KeyboardHookManager 1.1.0](https://www.nuget.org/packages/KeyboardHookManager/1.1.0)
9
-
10
- using System.Windows.Forms;
11
- using KeyboardHookManager;
12
-
13
- namespace Questions282456
14
- {
15
- public partial class Form1 : Form
16
- {
17
- private TextBox textBox;
18
- public Form1()
19
- {
20
- InitializeComponent();
21
-
22
- textBox = new TextBox { Dock = DockStyle.Fill, Multiline = true, };
23
- Controls.Add(textBox);
24
-
25
- HookManager.KeyPress += HookManager_KeyPress;
26
- HookManager.KeyDown += HookManager_KeyDown;
27
- }
28
-
29
- private void HookManager_KeyPress(object sender, KeyPressEventArgs e)
30
- {
31
- switch(e.KeyChar)
32
- {
33
- case 'w': textBox.Text += 'w'; break;
34
- case 'a': textBox.Text += 'a'; break;
35
- case 's': textBox.Text += 's'; break;
36
- case 'd': textBox.Text += 'd'; break;
37
- }
38
- }
39
-
40
- private void HookManager_KeyDown(object sender, KeyEventArgs e)
41
- {
42
- switch(e.KeyCode)
43
- {
44
- case Keys.Up: textBox.Text += "Up"; break;
45
- case Keys.Left: textBox.Text += "Left"; break;
46
- case Keys.Down: textBox.Text += "Down"; break;
47
- case Keys.Right: textBox.Text += "Right"; break;
48
- }
49
- }
50
- }
51
- }
1
+ `RawInput`とか`WH_KEYBOARD_LL`とかがキーワードになりますが、難しいので出来合いのものを使わせてもらいましょう。
2
+
3
+ [NuGet Gallery | KeyboardHookManager 1.1.0](https://www.nuget.org/packages/KeyboardHookManager/1.1.0)
4
+ 例えばこれだとこんな感じでしょうか。
5
+ 注意)こちらを薦めているわけではありません。ソースコード・ライセンス表記があって、そこそこDL数もあり新しいものだったってだけです。
6
+
7
+ ```cs
8
+ // [NuGet Gallery | KeyboardHookManager 1.1.0](https://www.nuget.org/packages/KeyboardHookManager/1.1.0)
9
+
10
+ using System.Windows.Forms;
11
+ using KeyboardHookManager;
12
+
13
+ namespace Questions282456
14
+ {
15
+ public partial class Form1 : Form
16
+ {
17
+ private TextBox textBox;
18
+ public Form1()
19
+ {
20
+ InitializeComponent();
21
+
22
+ textBox = new TextBox { Dock = DockStyle.Fill, Multiline = true, };
23
+ Controls.Add(textBox);
24
+
25
+ HookManager.KeyPress += HookManager_KeyPress;
26
+ HookManager.KeyDown += HookManager_KeyDown;
27
+ }
28
+
29
+ private void HookManager_KeyPress(object sender, KeyPressEventArgs e)
30
+ {
31
+ switch(e.KeyChar)
32
+ {
33
+ case 'w': textBox.Text += 'w'; break;
34
+ case 'a': textBox.Text += 'a'; break;
35
+ case 's': textBox.Text += 's'; break;
36
+ case 'd': textBox.Text += 'd'; break;
37
+ }
38
+ }
39
+
40
+ private void HookManager_KeyDown(object sender, KeyEventArgs e)
41
+ {
42
+ switch(e.KeyCode)
43
+ {
44
+ case Keys.Up: textBox.Text += "Up"; break;
45
+ case Keys.Left: textBox.Text += "Left"; break;
46
+ case Keys.Down: textBox.Text += "Down"; break;
47
+ case Keys.Right: textBox.Text += "Right"; break;
48
+ }
49
+ }
50
+ }
51
+ }
52
52
  ```