Advertisement

Tricking the Windows Keyboard

Started by July 31, 2001 11:01 AM
12 comments, last by MadProgrammer 23 years, 6 months ago
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.
Advertisement
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
hwnd = GetForegroundWindow();
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);
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:

      HWND hwndFocus = GetForegroundWindow();    DWORD dwThread = GetWindowThreadId( hwndFocus );    PostThreadMessage( dwThread, WM_KEYDOWN, ''A'', 0 );  



War Worlds - A 3D Real-Time Strategy game in development.
Advertisement
that looks like it would work perfectly, but where is GetWindowThreadId()? My compiler can''t find it.

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
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.
i know it is possible to make other processes think that the keyboad is being pressed b/c a lot of gamepads & joysticks can do it. i just wana know how......

This topic is closed to new replies.

Advertisement