fix the WindowIO-windows.cpp module to work correctly with the new DF, also made it a little simpler.

develop
belal 2010-09-19 19:49:45 -04:00
parent 918de0271b
commit 0f7a27d611
1 changed files with 5 additions and 6 deletions

@ -130,20 +130,19 @@ WindowIO::~WindowIO ()
void WindowIO::TypeStr (const char *input, int delay, bool useShift) void WindowIO::TypeStr (const char *input, int delay, bool useShift)
{ {
//sendmessage needs a window handle HWND, so have to get that from the process HANDLE //sendmessage needs a window handle HWND, so have to get that from the process HANDLE
HWND currentWindow = GetForegroundWindow();
window myWindow; window myWindow;
myWindow.pid = d->p->getPID(); myWindow.pid = d->p->getPID();
EnumWindows (EnumWindowsProc, (LPARAM) &myWindow); EnumWindows (EnumWindowsProc, (LPARAM) &myWindow);
char cChar; char cChar;
DWORD dfProccess = GetWindowThreadProcessId(myWindow.windowHandle,NULL); DWORD dfProcess = GetWindowThreadProcessId(myWindow.windowHandle,NULL);
DWORD currentProccess = GetWindowThreadProcessId(currentWindow,NULL); DWORD currentProcess = GetCurrentThreadId();
AttachThreadInput(currentProccess,dfProccess,TRUE); //The two threads have to have attached input in order to change the keyboard state, which is needed to set the shift state AttachThreadInput(currentProcess,dfProcess,TRUE); //The two threads have to have attached input in order to change the keyboard state, which is needed to set the shift state
while ( (cChar = *input++)) // loops through chars while ( (cChar = *input++)) // loops through chars
{ {
short vk = VkKeyScan (cChar); // keycode of char short vk = VkKeyScan (cChar); // keycode of char
if (useShift || (vk >> 8) &1) // char is capital, so need to hold down shift if (useShift || (vk >> 8) &1) // char is capital, so need to hold down shift
{ {
vk = vk & 0xFF; // remove the shift state from the virtual key code
BYTE keybstate[256] = {0}; BYTE keybstate[256] = {0};
BYTE keybstateOrig[256] = {0}; BYTE keybstateOrig[256] = {0};
GetKeyboardState((LPBYTE)&keybstateOrig); GetKeyboardState((LPBYTE)&keybstateOrig);
@ -160,7 +159,7 @@ void WindowIO::TypeStr (const char *input, int delay, bool useShift)
SendMessage(myWindow.windowHandle,WM_KEYUP,vk,0); SendMessage(myWindow.windowHandle,WM_KEYUP,vk,0);
} }
} }
AttachThreadInput(currentProccess,dfProccess,FALSE); //detach the threads AttachThreadInput(currentProcess,dfProcess,FALSE); //detach the threads
Sleep (delay); Sleep (delay);
} }