Click to See Complete Forum and Search --> : keybdevent and sendinput problem.


Quell
February 23rd, 2007, 10:30 PM
Hello.
I need to send some input to a program, and the problem is that keybdevent and sendinput refuse to give me any response at all. Any ideas how else i can send some keystorkes to another process?

HWND testp=FindWindow(NULL,L"test_window");
if(!testp)
MessageBox(0,L"Error finding test prog",0,0);
SetForegroundWindow(testp);
INPUT input;
input.type=INPUT_KEYBOARD;
KEYBDINPUT kb;
ZeroMemory(&kb,sizeof(KEYBDINPUT));
kb.wVk=VK_SPACE;
input.ki=kb;
SendInput(1,&input,sizeof(INPUT));
kb.dwFlags=KEYEVENTF_KEYUP;
input.ki=kb;
SendInput(1,&input,sizeof(INPUT));
return 1;

This code is called, but does absolutle nothing. Any ideas?
Thx

golanshahar
February 24th, 2007, 06:33 AM
The code that generate the space key looks ok to me.

Are you sure that the window that you bring to the foreground get the focus exactly in the control you want to get the space key?
If the focus is ok, maybe you should add a little ::Sleep() after the ::SetForegroundWindow() call.

Cheers

Quell
February 24th, 2007, 09:21 AM
hmm, well, thx for the idea, didn;t work so well thou.
Dam it i guess ill just inject some code and keep looking for a solution. The werid thing is, that this only happens in this app, notepad etc work fine. A/w thx for ur time.

[EDIT]
After thinking about the problem for an hour or so, i came over this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/rawinput.asp
I was wondering if the program was using RawInput, if the SendInput function still work?

golanshahar
February 25th, 2007, 02:46 PM
On what kind of app it doesnt seem to work?

Cheers