Quote:Original post by raptorstrike ok im very close now, i just need to know how you would sent the tab key as an event like VK_TAB what kind of function would you pass this into to make it take effect on the window like how you were saying |
Ok this is what you need to do:
Going back to the first example - here is a demo of what will be done:
int main(){ HWND notepad = FindWindow("Notepad","Untitled - Notepad"); if( !notepad ) { cout << "Cannot find window!"; return 0; } ::Sleep(5000); SetForegroundWindow(notepad); // bring up the window SetFocus(notepad); // set focus keybd_event(VK_SHIFT, 1, 0, 0); keybd_event(VkKeyScan('*'), 1, 0, 0); keybd_event(VkKeyScan('*'), 1, KEYEVENTF_KEYUP, 0); keybd_event(VkKeyScan('*'), 1, 0, 0); keybd_event(VkKeyScan('*'), 1, KEYEVENTF_KEYUP, 0); keybd_event(VkKeyScan('*'), 1, 0, 0); keybd_event(VkKeyScan('*'), 1, KEYEVENTF_KEYUP, 0); keybd_event(VK_SHIFT, 1, KEYEVENTF_KEYUP, 0); keybd_event(VK_RETURN, 1, 0, 0); keybd_event(VK_RETURN, 1, KEYEVENTF_KEYUP, 0); return 0;}
Basically this will send three * keystorkes to the window that has focus. If you openup notepad and then run this you will see the *'s come on the screen after 5 seconds. The notepad window will come to focus.
Now for your program:
int main(){ HWND notepad = FindWindow("Notepad","Untitled - Notepad"); if( !notepad ) { cout << "Cannot find window!"; return 0; } ::Sleep(5000); SetForegroundWindow(notepad); // bring up the window SetFocus(notepad); // set focus keybd_event(VK_TAB, 1, 0, 0); // send in a tab keybd_event(VK_TAB, 1, KEYEVENTF_KEYUP, 0); keybd_event(VK_RETURN, 1, 0, 0); // send in a return keybd_event(VK_RETURN, 1, KEYEVENTF_KEYUP, 0); return 0;}
- Drew