Tricking the Windows Keyboard
how can i make my program tell windows that a key on the keyboard has been pressed?
i know this is possible because many joysticks (like the sidewinder gamepad and the gravis exterminator) have an option where a button on the keyboard corresponds to a set of keystrokes.
i would really like to know how to do this...
thanks
Mad programmer
The Sidewinder in specific uses the DirectInput API. This is certainly one method, another windoze method is to post window messages to the system and let it do whatever that crazy windows-message be doin''.
-------------------
-WarMage
...always a playa, unless I''m an argentinian prarie.
-------------------
-WarMage
...always a playa, unless I''m an argentinian prarie.
how would i use to dinput api to do that?
also, i tried w/ the windows messages, but i don''t think they are going anywhere... what hWnd would i use when calling PostMessage() to get it to go to whatever window is in the foreground? (not necissarily my program)
heres the code i have right now.....
for(int i=''A'';i<=''Z'';i++)
PostMessage(NULL, WM_KEYDOWN, i, 0);
thanks for your help....
the madprogrammer
also, i tried w/ the windows messages, but i don''t think they are going anywhere... what hWnd would i use when calling PostMessage() to get it to go to whatever window is in the foreground? (not necissarily my program)
heres the code i have right now.....
for(int i=''A'';i<=''Z'';i++)
PostMessage(NULL, WM_KEYDOWN, i, 0);
thanks for your help....
the madprogrammer
it still doesn''t work....
for(int i=''A'';i<=''Z'';i++)
{
PostMessage(GetForegroundWindow(), WM_KEYDOWN, i, 0);
Sleep(100);
}
MessageBox(NULL, "Done", "Done", 0);
for(int i=''A'';i<=''Z'';i++)
{
PostMessage(GetForegroundWindow(), WM_KEYDOWN, i, 0);
Sleep(100);
}
MessageBox(NULL, "Done", "Done", 0);
You can''t use PostMessage(), since it will post the message to your own thread''s message queue. You need to post the message to the thread of the foreground window, as in:
War Worlds - A 3D Real-Time Strategy game in development.
|
War Worlds - A 3D Real-Time Strategy game in development.
that looks like it would work perfectly, but where is GetWindowThreadId()? My compiler can''t find it.
thanks.
the MadProgrammer.
thanks.
the MadProgrammer.
Looking on msdn, it shows that GetWindowThreadId() is only available in the win ce os. So I tried using GetWindowThreadProcessId(), leaving the rest of the code the same just switching those to functions.. this compiles, But no output appears in the other window... any help would be appreciated as I think this sounds neat.
Thanks,
lao
Thanks,
lao
Oh, I should say that I was trying to send the message to a window that did not belong to my process.. I don''t know if that is possible? Or if you can only send them to your child windows.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement