質問編集履歴
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
|
16
16
|
3.以下コードです。
|
17
17
|
|
18
|
+
```C#
|
18
19
|
using System;
|
19
20
|
using System.Diagnostics;
|
20
21
|
using System.Linq;
|
@@ -81,3 +82,4 @@
|
|
81
82
|
}
|
82
83
|
}
|
83
84
|
|
85
|
+
```
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,4 +13,71 @@
|
|
13
13
|
ご教示頂きたい事項
|
14
14
|
バックグラウンドにあるウインドウに対し、CtrlやShift,Altとの組み合わせショートカットキーを送信することはできないのでしょうか。ご存じの方いましたらご教示いただければ幸いです。
|
15
15
|
|
16
|
+
3.以下コードです。
|
16
17
|
|
18
|
+
using System;
|
19
|
+
using System.Diagnostics;
|
20
|
+
using System.Linq;
|
21
|
+
using System.Runtime.InteropServices;
|
22
|
+
|
23
|
+
namespace ConsoleApp1
|
24
|
+
{
|
25
|
+
class Program
|
26
|
+
{
|
27
|
+
[DllImport("user32.dll")]
|
28
|
+
static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
29
|
+
|
30
|
+
[DllImport("user32.dll")]
|
31
|
+
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
32
|
+
|
33
|
+
[DllImport("user32.dll", SetLastError = true)]
|
34
|
+
public static extern IntPtr GetAncestor(IntPtr hWnd, uint gaFlags);
|
35
|
+
|
36
|
+
// 送信するメッセージ
|
37
|
+
const uint WM_KEYDOWN = 0x100;
|
38
|
+
const uint WM_UP = 0x0101;
|
39
|
+
const uint WM_CHAR= 0x0102;
|
40
|
+
|
41
|
+
const uint WM_LBUTTONDOWN = 0x0201;
|
42
|
+
const uint WM_LBUTTONUP = 0x0202;
|
43
|
+
const uint None = 0;
|
44
|
+
const uint MK_LBUTTON = 0x0001;
|
45
|
+
public const uint GA_ROOT = 2;
|
46
|
+
|
47
|
+
static void Test1()
|
48
|
+
{
|
49
|
+
//メモ帳確認用
|
50
|
+
//var hwnd = Process.GetProcessesByName("Notepad").First().MainWindowHandle;
|
51
|
+
//↓文字入力の場合はこっちのウインドウハンドル
|
52
|
+
//hwnd = FindWindowEx(hwnd, IntPtr.Zero, "richEditD2DPT", null);
|
53
|
+
//// aと入力
|
54
|
+
//PostMessage(hwnd, WM_KEYDOWN, (IntPtr)0x41, IntPtr.Zero);
|
55
|
+
|
56
|
+
//chromeの場合
|
57
|
+
var hwnd = Process.GetProcessesByName("chrome")[0].MainWindowHandle;
|
58
|
+
|
59
|
+
// ctrlと入力
|
60
|
+
PostMessage(hwnd, WM_KEYDOWN, (IntPtr)0x11, IntPtr.Zero);
|
61
|
+
// ctrlと入力
|
62
|
+
PostMessage(hwnd, WM_CHAR, (IntPtr)0x11, IntPtr.Zero);
|
63
|
+
|
64
|
+
// sと入力
|
65
|
+
PostMessage(hwnd, WM_KEYDOWN, (IntPtr)0x53, IntPtr.Zero);
|
66
|
+
// sと入力
|
67
|
+
PostMessage(hwnd, WM_CHAR, (IntPtr)0x53, IntPtr.Zero);
|
68
|
+
|
69
|
+
// tと入力
|
70
|
+
PostMessage(hwnd, WM_UP, (IntPtr)0x53, IntPtr.Zero);
|
71
|
+
// ctrlと入力
|
72
|
+
PostMessage(hwnd, WM_UP, (IntPtr)0x11, IntPtr.Zero);
|
73
|
+
|
74
|
+
}
|
75
|
+
|
76
|
+
static void Main(string[] args)
|
77
|
+
{
|
78
|
+
Test1();
|
79
|
+
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|