No VkKeyScan?

  • Thread starter Thread starter Benjamin Lukner
  • Start date Start date
B

Benjamin Lukner

Hi!

I'd like to send a text from my application to the active one.
Under XP I use VkKeyScan and keybd_event.
But under CE VkKeyScan (VkKeyScanEx/OEMKeyScan) seems not to be
implemented. What function can I use instead? Is there an alike function
in the compact framework?

Kind regards,

Benjamin Lukner
 
Benjamin said:
I'd like to send a text from my application to the active one.
Under XP I use VkKeyScan and keybd_event.
But under CE VkKeyScan (VkKeyScanEx/OEMKeyScan) seems not to be
implemented. What function can I use instead? Is there an alike function
in the compact framework?

OK, I've found the PostKeybdMessage API and a sample for sending
strings. I don't completely understand why and how it works, but it does
work :-)

http://www.opennetcf.org/Forums/topic.asp?TOPIC_ID=156&SearchTerms=keybd_event

Weird...

Kind regards,

Benjamin Lukner
 
The two for Windows CE are keybd_event() and PostKeybdMessage().

Paul T.
 
Paul said:
The two for Windows CE are keybd_event() and PostKeybdMessage().

I have another question...

When I use PostKeybdMessage, the target gets a KeyDown event with empty
(KeyEventArgs) e!
Is there any possibility to simulate keystrokes with PostKeybdMessage or
do I have to create an own table to replace VkKeyScan?

Kind regards,

Benjamin Lukner
 
What are you sending?! You can't send every key with PostKeybdMessage()...
I have no experience with VkKeyScan(), so I have no idea what it's for.

Paul T.
 
Paul said:
What are you sending?! You can't send every key with PostKeybdMessage()...
I have no experience with VkKeyScan(), so I have no idea what it's for.

VkKeyScan translates an ASCII character into the sequence I have to send
with keyb_event. E.g.:

"A" -> (VkKeyScan) -> VK_SHIFT, VK_A
"a" -> (VkKeyScan) -> VK_A

But I'm wondering if PostKeybdMessage posts the text "directly" into the
control without affecting the keyboard handler.

I think the simplest thing is to build my own translation table to
simulate the VkKeyScan function, because the target application should
get the text through the system keyboard driver.

So long,

Benjamin Lukner
 
OK, you have to do that yourself or call into the keyboard driver, but
PostKeybdMessage bypasses most situations where you'd need to do it, anyway.

No, it sends the data through the input system, not 'directly' to a control,
although that is transparent to you. Typically, since you just want to send
the data without a lot of monkeying around, you'd do something like this for
non-control keys:

PostKeybdMessage( (HWND)-1, 0,
pshift[ 0 ],
len,
pshift,
&charbuf[ 0 ] )

pshift would be set to an array of KeyStateDownFlag. In this case, you
don't have to handle shift keys, etc. If the characters in charbuf are
"aAbBcC", they get sent just fine without any funny work with the shift key.

For things like Tab, Enter, etc, you have to use keybd_event(). For those,
you might do something of this nature:

keybd_event( VK_TAB, VK_TAB, 0, 0 );
keybd_event( VK_TAB, VK_TAB, KEYEVENTF_KEYUP, 0 );

to send the character.

I suppose that, if you are doing this wedging from the same program that
already has the focus, there's little benefit to working with
PostKeybdMessage and keybd_event. Why not just set the .Text property? If,
as in my case, you are running as a service and wedging, say, the input
found at one or more serial ports into the keyboard stream, this is far
better than trying to figure out what control has focus and what to do about
sending it characters.

Paul T.
 
Back
Top