回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,131 +1,66 @@
|
|
1
1
|
非常に雑ですがほぼ提示コードのままで、こちらの手元では動きました(Windows10 MicrosoftIME)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
[NuGet Gallery | PInvoke.User32 0.7.104](https://www.nuget.org/packages/PInvoke.User32/0.7.104)
|
6
|
-
|
7
|
-
```
|
4
|
+
```cs
|
8
|
-
|
9
5
|
using System.Drawing;
|
10
|
-
|
11
6
|
using System.Runtime.InteropServices;
|
12
|
-
|
13
7
|
using System.Windows.Forms;
|
14
|
-
|
15
8
|
using static PInvoke.User32;
|
16
9
|
|
17
|
-
|
18
|
-
|
19
10
|
namespace Questions371226
|
20
|
-
|
21
11
|
{
|
22
|
-
|
23
12
|
public partial class Form1 : Form
|
24
|
-
|
25
13
|
{
|
26
|
-
|
27
14
|
public Form1()
|
28
|
-
|
29
15
|
{
|
30
|
-
|
31
16
|
InitializeComponent();
|
32
|
-
|
33
17
|
TopMost = true;
|
34
18
|
|
35
|
-
|
36
|
-
|
37
19
|
var button = new Button() { Text = "VK_KANJI", };
|
38
|
-
|
39
20
|
button.Click += (s, e) => Send(VirtualKey.VK_KANJI);
|
40
|
-
|
41
21
|
Controls.Add(button);
|
42
22
|
|
43
|
-
|
44
|
-
|
45
23
|
var button2 = new Button() { Text = "VK_A", Location = new Point(0, 50), };
|
46
|
-
|
47
24
|
button2.Click += (s, e) => Send(VirtualKey.VK_A);
|
48
|
-
|
49
25
|
Controls.Add(button2);
|
50
|
-
|
51
26
|
}
|
52
27
|
|
53
|
-
|
54
|
-
|
55
28
|
private static unsafe void Send(VirtualKey key)
|
56
|
-
|
57
29
|
{
|
58
|
-
|
59
30
|
var isExtend = false;
|
60
|
-
|
61
31
|
var inp = new INPUT
|
62
|
-
|
63
32
|
{
|
64
|
-
|
65
33
|
type = InputType.INPUT_KEYBOARD
|
66
|
-
|
67
34
|
};
|
68
|
-
|
69
35
|
inp.Inputs.ki.wVk = key;
|
70
|
-
|
71
36
|
inp.Inputs.ki.wScan = (ScanCode)MapVirtualKey((int)inp.Inputs.ki.wVk, MapVirtualKeyTranslation.MAPVK_VK_TO_VSC);
|
72
|
-
|
73
37
|
inp.Inputs.ki.dwFlags = isExtend ? KEYEVENTF.KEYEVENTF_EXTENDED_KEY : 0x0;
|
74
|
-
|
75
38
|
inp.Inputs.ki.time = 0;
|
76
|
-
|
77
39
|
//inp.Inputs.ki.dwExtraInfo = 0;
|
78
|
-
|
79
40
|
SendInput(1, &inp, Marshal.SizeOf(inp));
|
80
|
-
|
81
|
-
|
82
41
|
|
83
42
|
//System.Threading.Thread.Sleep(100);
|
84
43
|
|
85
|
-
|
86
|
-
|
87
44
|
inp.Inputs.ki.dwFlags = (isExtend ? KEYEVENTF.KEYEVENTF_EXTENDED_KEY : 0x0) | KEYEVENTF.KEYEVENTF_KEYUP;
|
88
|
-
|
89
45
|
SendInput(1, &inp, Marshal.SizeOf(inp));
|
90
|
-
|
91
46
|
}
|
92
47
|
|
93
|
-
|
94
|
-
|
95
48
|
protected override CreateParams CreateParams
|
96
|
-
|
97
49
|
{
|
98
|
-
|
99
50
|
get
|
100
|
-
|
101
51
|
{
|
102
|
-
|
103
52
|
var p = base.CreateParams;
|
104
|
-
|
105
53
|
if (!DesignMode) p.ExStyle |= (int)SetWindowLongFlags.WS_EX_NOACTIVATE;
|
106
|
-
|
107
54
|
return p;
|
108
|
-
|
109
55
|
}
|
110
|
-
|
111
56
|
}
|
112
|
-
|
113
57
|
}
|
114
|
-
|
115
58
|
}
|
116
|
-
|
117
59
|
```
|
118
|
-
|
119
|
-
|
120
60
|
|
121
61
|
---
|
122
62
|
|
123
|
-
|
124
|
-
|
125
63
|
わたしもWPFでソフトキーボード作ったのですが、その時は↓のようなツールが非常に便利でした。
|
126
|
-
|
127
64
|
[KT Software - Keymill](http://kts.sakaiweb.com/keymill.html)
|
128
65
|
|
129
|
-
|
130
|
-
|
131
66
|
リアルキーボードとの違いを探ってみてはいかがでしょうか。
|