How to Find the Key Being Pressed and then Send a Key Press Programatically

How to Find the Key Being Pressed and then Send a Key Press Programatically

Post by rgalgo » Sat, 24 Mar 2007 03:18:01


I've been reading all I can on how to determine which key is being
pressed and also how to send a key press programatically.

I'm mainly interested in the Action Key.
I've come across this in a few places:
/ the phone keypad maps to VK_* as shown below.
// some keys might not be present, e.g. VK_TFLIP
sofkey1 softkey2 VK_TSOFT1, VK_TSOFT2
^ VK_TUP
< + > VK_TLEFT, VK_TACTION, VK_TRIGHT
v VK_TDOWN
home back VK_THOME, VK_TBACK
talk end VK_TTALK, VK_TEND
1 2 3 VK_T0..VK_T9
4 5 6 ...
7 8 9 ...
* 0 # VK_TSTAR, VK_TPOUND
// other buttons include
VK_TRECORD
VK_TPOWER, VK_TVOLUMEUP, VK_TVOLUMEDOWN
VK_TFLIP

what is the special meaning behind VK_T**** versus VK_****?
So for example, what is the difference between VK_TACTION and
VK_RETURN?

Also, for example, I've seen VK_RETURN = 0x0D, how can I find the hex
value of the various keys?

Next,
How do I go about determining what key is pressed? RemoteSpy seemed
like a promising start but I couldn't figure out how to get it to
display anything about key_presses occuring. Do I need to write
something that just sits and intercepts all messages to the system and
displays them?

Finally,
Is something like:
SendMessage(handle, WM_KEYDOWN, VK_RETURN, 0);
the proper way of sending 'key presses'?
 
 
 

How to Find the Key Being Pressed and then Send a Key Press Programatically

Post by Bart » Sat, 24 Mar 2007 05:26:52

In a window just handle WM_KEYDOWN and get the key from the message, if it
is
a control child window you can subclass the window and get these values or
using
notify depending on the window..

If you are spying on another application then you will have to be outside
grabbing all keyboard
values, so you need to write a hook...

And yep, something like your SendMessage will work just fine...

 
 
 

How to Find the Key Being Pressed and then Send a Key Press Programatically

Post by Scott Seli » Sat, 24 Mar 2007 06:24:22


You can open up winuserm.h and see the values.


Generally, no. It might work for some apps, though it'll be hit or
miss. Using keybd_event like this to 'press' the action key to
whatever app has focus:

keybd_event(VK_RETURN, 0, 0, 0);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);

Of course, if you want to simulate key presses to an app that doesn't
have focus, you'll need to use SendMessage or PostMessage, but you
might run into various odd issues, especially with accelerators.

--
Scott Seligman [MSFT]
This posting is provided AS IS with no warranties, and confers
no rights.
 
 
 

How to Find the Key Being Pressed and then Send a Key Press Programatically

Post by Norman Dia » Sat, 24 Mar 2007 09:22:56


If you want to recognize a Smartphone's Action key, and preserve this fact
even if someday the Action key might be mapped to a different VK code than a
PC's Enter key, then you want to use VK_TACTION in your program.

I think that in principle the VK_T**** definitions had the same idea. For a
PC's keyboard there are no VK_*** definitions for keys that have digits 0 to
9 on them, and programs should use values '0' through '9' or 0x30 through
0x39. For Smartphones and Pocket PCs, the VK_T*** definitions are oddly
coded in Unicode. In my experience characters might be encoded in either
ANSI code pages or Unicode, but those were character values not VK codes.
This is the only place where VK codes are coded in Unicode. My programs use
values 0x30 through 0x39.


winuserm.h shows that VK_TACTION is mapped to VK_RETURN at the present time.

winuser.h shows that VK_RETURN is mapped to 0x0D at the present time.


In principle I agree (though for this I would probably write VK_TACTION).

However, the relationship among Windows CE, OEM keyboard drivers, the SIP
panel, and applications is so messed up that I don't know any really
reliable solution. For example when I tried to process WM_KEYDOWN, I was
always getting VK_PROCESSKEY instead of the actual key. Reading MSDN, I
found alternative code that was asserted to work, but it really provided a
second copy of the VK_PROCESSKEY constant instead of the actual key.
Microsoft posted some code that was asserted to work, using undocumented
features of a partly documented function, but it really provided a third
copy of the VK_PROCESSKEY constant instead of the actual key.

I ended up doing lots of experiments, some hits and misses on VK codes, and
mostly hits on WM_CHAR messages. If a VK code turns out to be equal to a
value that can be delivered by a WM_CHAR message as a character, then it's
ambiguous, we can't really figure out which key was pressed. I had to avoid
processing most WM_KEYDOWN messages except for a few VK codes that I hoped
would be accurate, and process WM_CHAR messages for most keys.
 
 
 

How to Find the Key Being Pressed and then Send a Key Press Programatically

Post by rgalgo » Tue, 27 Mar 2007 23:10:20

n Mar 22, 8:22 pm, "Norman Diamond" < XXXX@XXXXX.COM >
wrote:

Thanks for the info.
I've been looking at switching to using keybd_event which is working
well in some of my apps and not so well in others.
For example on one screen I cannot, for whatever reason, get a
'button' to be pressed with keybd_event.

I even went so far as to looping through the entire Keys enum pausing
a little bit in between each keybd_event and never successfully
managed to get the button to be 'pressed'. Oh well, looks like a lot
more testing is needed to figure this out.