PDA

View Full Version : trying to send a key press



kryton9
14-05-2007, 07:40
Since we use the Escape key to terminate our programs usually. I was trying to send a key press so simulate the user pressing ESCAPE
to then start the termination of my application and to cleanup before doing so. Just as when then user presses the Escape key.

I put this where I wanted to simulate the escape key press, but it doesn't work. Any ideas?
hwnd is my windows handle.
I also tried %WM_KEYDOWN, and it didn't work either.

SendMessage(hwnd, %WM_KEYUP, %VK_ESCAPE, 0)

Thanks.

catventure
14-05-2007, 09:04
Hi kryton9,

It can sometimes be done by putting code into window main loop


IF getwindowkeystate( hWnd, %VK_RETURN) THEN
......
......
......
ENDIF

catventure.

kryton9
14-05-2007, 10:24
THanks Catventure. I aready have such a loop for the escape key. I just wanted to mimic that from code elsewhere.
I found a work around already, but it would be nice to know how to send the message. From reading at MSDN it seemed like that should work.
But I saw other posts from coders, saying it doesn't work either. So I don't know, thought I would ask here.

ErosOlmi
14-05-2007, 10:58
Ken,

sending a message to a window is not so easy. SendMessage will put a message in the message queue of a specified window. To be able to get the message you need to handle the window message queue with getMessage but if this a TBGL window it is internally managed but TBGL module.

I suppose you want to send a key like in old DOS time. If so, you can use SendKeys (http://www.thinbasic.com/public/products/thinBasic/help/html/sendkeys.htm) in UI module:



Sendkeys("{ESC}")


Let me know.
Eros