私はこのコードを使用しています
const int WM_KEYDOWN = 256;
const int WM_KEYUP = 257;
const int WM_CHAR = 258;
public static void SendKeys(string message){
int foregroundWindowHandle = GetForegroundWindow();
uint remoteThreadId = GetWindowThreadProcessId(foregroundWindowHandle, 0);
uint currentThreadId = GetCurrentThreadId();
//AttachTrheadInput is needed so we can get the handle of a focused window in another app
AttachThreadInput(remoteThreadId, currentThreadId, true);
//Get the handle of a focused window
int focused = GetFocus();
//Now detach since we got the focused handle
AttachThreadInput(remoteThreadId, currentThreadId, false);
foreach (char c in message)
{
//SendMessage(focused, WM_CHAR, (int)c, null);
SendMessage(focused, WM_KEYDOWN, 65, null);
SendMessage(focused, WM_KEYUP, 66, null);
SendMessage(focused, WM_CHAR, 67, null);
}
}
そして、テストすると(たとえば、メモ帳がアクティブになっている場合)、文字Cのみが印刷されるため、WM_CHARのみが機能します-なぜですか?