Passing keypresses to other windows (internet explorer)
Posted on 2003-03-12
In my program I want to pass keypresses to a internet explorer window which I have got the HWND for using FindWindow();
I want to control iexplore through my program and I will cycle through the links using the TAB key and then followed by the RETURN key. I was doing it as follows:
HWND h = FindWindow(NULL,"Yahoo! - Microsoft Internet Explorer provided by Freeserve.net");
for(int i=0; i<10; i++)
PostMessage(h, WM_KEYDOWN, VK_TAB, 0);
PostMessage(h, WM_KEYUP, VK_TAB, 0);
PostMessage(h, WM_KEYUP, VK_RETURN, 0);
So this would cycle through 10 links at 0.5 second intervals and click the link afterwards using VK_RETURN.
I have tried this through the keyboard and it works fine, clicking TAB 10 times followed by Enter (its a specific website so I know how many times to click TAB, in this case Yahoo.com).
But when my program does it, it comes off the address bar (which is the first click of TAB), onto the first link of the page on the second TAB command(everything is fine so far), but then afterwards it goes back onto the address bar and continues to select/deselect the address bar. I can't understand what is happening as I am sending the exact commands that I presume the keyboard sends to IE. Can anyone help me please as its driving me crazy.
Thanks in advance