A program to 'hold down' a key

Started by
7 comments, last by Hybrid 20 years, 9 months ago
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
Advertisement
Possible? Of course. Easy? I''m not sure *grin*
keybd_event() might work.
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)
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.
.
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.
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.
Nothing stopping a driver from having a user configuration interface, like an icon in the system tray.
.
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.

This topic is closed to new replies.

Advertisement