Keyboard to Button presses

I understand that Windows is a mouse-oriented system, but given that my application is to be run in a shipboard environment and potentially rough conditions it is mandatory that functionality is directed toward the keyboard.

So what I would like to do is display a series of push button windows that 'press' when a key is pressed; in other words a keypress would be converted into a mouse button click. Can one take an accelerator keypress message and somehow convert it to an appropriate mouse click message and mouse position and send it to the operating system such that the button would depress? It might be better not to use "TranslateAccelerator()" and just catch the keypress message directly and convert it to a mouse activity.

I realize that if I have accelerator keys and the button says "F2" in it and the user presses F2, the correct response will happen but the button on the display will just sit there looking boring. So all this effort is just for looks, but we all know that is important.

Thanks for any insight!
[1067 byte] By [Gyannea] at [2007-11-18 0:38:46]
# 1 Re: Keyboard to Button presses
I have developed a number of applications that had similar issues. What I found to be much better is to NOT use the standard "click" look of buttons. Rather I have some custom controls (ok really a subclassing of the button control) that give me good control over the appearance.

The was especially important because in "field" applications [I developed Naval software for about 12 years] if is necessary to have VERY obvious indicators.

Hope this helps (even though it is a suggestion to an alternate solution rather than a direct answer.)...
TheCPUWizard at 2007-11-9 13:02:30 >
# 2 Re: Keyboard to Button presses
You might also want to check out these funcs; I think they might be what you would want to investigate.
SendInput ()

these two work for all Winders versions.
keybd_event()
mouse_event() ( I used this to synthesize toolbar and button pressing in outlook if I remember correctly, been a while. )
mdmd at 2007-11-9 13:03:32 >
# 3 Re: Keyboard to Button presses
I did an uncomfortable thing which I am sure will come back to haunt me. I used the 'WM_KEYDOWN message in my main window callback function to send a WM_LBUTTONDOWN message to the button window (if it was the correct key). THe button goes down, but the keyboard focus goes to the child button so in the message loop I have to trap the WM_KEYUP message from the child window and re-direct it to the parent (just changed MSG.hwnd to the handle of the parent and dispatched it. Back in the parent callback function the WM_KEYUP message sends a WM_LBUTTONUP to the button child window and I finally respond to the WM_COMMAND message in the parent callback function. Then I do the action. Of course, I have to give the keyboard focus back to the parent at that time.

It works. You press the key and the button depresses and you release the key and it comes up. However, if you left click with the mouse at the same time, you can screw it up. I think the keyboard focus gets messed up. There is probably a way I can lock out mouse actions during this time, but this seems like an awfully complicated way to do something quite simple! On the other hand, the framework provides a way to make the button lite up when pressed!
Gyannea at 2007-11-9 13:04:30 >