Click to See Complete Forum and Search --> : Need help understanding something


perito
June 18th, 2008, 03:44 PM
ok here is exactly what Im trying to do,

I have to insert 10 strings in 10 different textboxes in the shortest possible time (half a second counts), so I thought the best way is to store them all in a program before the timer starts and then simply press TAB 10 times when the timer starts, and my application would paste them each in a separate text box...
so I want it to paste it on the old focused control then move to the other control ...
After help of some friends, I got this code
#include <windows.h>
#include <stdio.h>
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hWnd;
for(;;)
{
MSG Msg;
while(GetMessage(&Msg, NULL, 0, 0)){
if(Msg.message == WM_KEYUP && Msg.wParam == VK_TAB){
PostMessage(Msg.hwnd, WM_PASTE, 0, 0);
printf("K\n"); //Never shows this == not entering the if statment ... why ?
// you might need to try GetFocus() instead of Msg.hwnd
}
if(!IsDialogMessage(hWnd, &Msg)){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
}
return 0;
}

the code is never entering the If statment, even when I press TAB
I tried adding printf("test\n"); to check, it never shows

why is it not entering the If Statment ?

Joeman
June 19th, 2008, 03:43 AM
It is because getmessage isn't going to work because you have no windows at all. You need a window. Are you trying to get keys from other windows that don't belong to your thread?

perito
June 19th, 2008, 03:58 PM
Im trying to catch TAB key anywhere, and when it is pressed, I want to paste.
how can I create a window ... could you show me an example please?
thx

S_M_A
June 19th, 2008, 04:15 PM
Try CreateWindow at MSDN

perito
June 20th, 2008, 08:47 AM
I dont want to create any text box ... I want to capture the tab press where ever it is pressed (my case on a website running by firefox) and when the tab is pressed I want to paste the clipboard and move to the next text box...

how can I do this? should I create a window or not ?

Joeman
June 20th, 2008, 06:36 PM
No, you don't want to create a window. You want to capture the system keys and not local keys that are for your thread. The easiest way is to use getasynckeystate, wait for the key to be pressed, wait for it to be released and do what you want. The other method which is more promising is to use a system hook on the keyboard. I could just post source code to do this, but it seems like you haven't even tried to solve this yourself, so look up what I provided and come back :D Also I am not for sure you can use sendmessage to firefox and it would work, but it may work. One more thing, why not create a firefox plugin?

If you want to use the system hook on the keyboard, search it on this forum. I just went over this for someone ;)

Arjay
June 20th, 2008, 08:35 PM
Look into the Active Accessibility interfaces. They will allow you to reliable insert text into controls of a web page. As long as the control has a unique tag id, AA will be able to manipulate it even if the control gets moved around on the web page.