Archived

This topic is now archived and is closed to further replies.

Hybrid

A program to 'hold down' a key

Recommended Posts

Hybrid    138
Reading key states in C or C++ is easy. But is it possible to create a program to actually simulate a key press to effectively hold down the key, so that other programs running ''think'' that it is being held down. Just someone asked me if I could quickly whip this up. But then I realised I don''t know how to do it, or if it can be done. He just wants a program to ''hold down'' the ALT key, so that it affects other programs. Possible??? Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
a quick application of glue or tape should do the trick nicely, i used to lean a snall book against a key to get the keypress i needed duplicated (like answering yes to annoying incessant prompts)

Share this post


Link to post
Share on other sites
Mastaba    761
Is it possible? Sure, it is possible. For Windows create a keyboard driver that just reports it as being pressed regardless if it is or isn''t. See the DDK for more info.

Share this post


Link to post
Share on other sites
drslush    122
Depending on what you want the program for.... You could just write a program that uses keybd_event to send a WM_KEYDOWN, and whenever a WM_KEYUP is recieved for the ALT key, you can use keybd_event to send the WM_KEYDOWN message again.

Downside with this is that it would appear as if the alt was released momentarily before being pressed again. Plus I''m not sure if it would fool GetKeyState() and GetAsyncKeyState(), since the API reference says that it gets the hardware state of the key.

Unfortunately, you can''t use SetKeyboardState(), since that works just with the calling thread, and not the entire system.

Share this post


Link to post
Share on other sites
Hybrid    138
Hmm, yeah I didn''t think this would be as simple as it sounds. The driver method is a little too complicated, because really the program should be able to enable/disable this ''key holding'' when you want it active or not.

The windows messaging method might work, but like you say, it should get it from hardware. So I have doubts over that method.

Share this post


Link to post
Share on other sites
Sphet    631
I''m not sure if this would work, but I was looking in the ''Accessibility Features'' in the control panel of Windows 2000. There''s an option for ''sticky keys'' which lets you toggle ALT, CTRL or SHIFT on and off by pressing and holding the shift key 5 times or so. It seems quite configurable and is tied into the OS so you wouldn''t have problems with integration.

Give it a look if you have it on your version of Windows.

Share this post


Link to post
Share on other sites