Answered by:
OnScreen Keyboard does not provide ScanCode on the KeyDown event

Question
-
When receiving the KeyDown event from the OnScreen keyboard I notice the scan code is always set to 0. The VirtualKey is set so I was thinking I could just use MapVirtualKey\MapVirtualKeyEx to convert that to a scancode. However, those functions are mapped as "Desktop Only". My questions are why does the OnScreen Keyboard not provide a scancode? Or is there at least a Metro mode method where I can convert the VirtualKey to a scancode?
Thanks,
Raul
Thursday, May 3, 2012 6:53 PM
Answers
-
Hi Raul,
The soft keyboard does not generate scan codes. There is not a 1:1 mapping between VKs and scan codes, and the soft keyboard can generate many keys which do not have matching scan codes (i.e. lower case characters, several of the symbols, and the icons on the face menu). The soft keyboard generates Unicode characters and sends them as though they were keystrokes with the VK_PACKET virtual key.
VK_PACKET is 0xE7 (231) and that is what you see in the KeyDown event. The Xaml KeyDown event converts this into characters, but CoreWindow.KeyDown passes the VK code from WM_KEYDOWN directly. I'll file a report on this difference for you.
--Rob
- Proposed as answer by Jesse Jiang Friday, June 1, 2012 9:31 AM
- Marked as answer by RIP27 Friday, February 1, 2013 9:42 PM
Saturday, May 5, 2012 2:37 AMModerator
All replies
-
Hi Paul,
Yes, there is no Virtual key for the OnScreen keyboard. And there is no way to screen scraping in metro.
Best regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Friday, May 4, 2012 9:32 AM -
Screen Scraping? Not sure why you are talking about Screen Scraping in reference to my question.
As for VirtualKey, KeyDown event from XAML controls is providing the correct VirtualKey value from the enumeration. However I have noticed 2 errors.
- No scan code is provided. This is a standard value. If know the current locale identifier this is a 1:1 mapping with Virtual Key. Unfortunately the API to do this is marked as Desktop Only http://msdn.microsoft.com/en-us/library/windows/desktop/ms646307(v=vs.85).aspx.
- CoreWindow.KeyDown event appears to have a bug. While XAML version of event has the correct VirtualKey, this event does not. No matter which character I touch on the OnScreen keyboard receive a VirtualKey value of 231.
Friday, May 4, 2012 2:43 PM -
Hi Raul,
The soft keyboard does not generate scan codes. There is not a 1:1 mapping between VKs and scan codes, and the soft keyboard can generate many keys which do not have matching scan codes (i.e. lower case characters, several of the symbols, and the icons on the face menu). The soft keyboard generates Unicode characters and sends them as though they were keystrokes with the VK_PACKET virtual key.
VK_PACKET is 0xE7 (231) and that is what you see in the KeyDown event. The Xaml KeyDown event converts this into characters, but CoreWindow.KeyDown passes the VK code from WM_KEYDOWN directly. I'll file a report on this difference for you.
--Rob
- Proposed as answer by Jesse Jiang Friday, June 1, 2012 9:31 AM
- Marked as answer by RIP27 Friday, February 1, 2013 9:42 PM
Saturday, May 5, 2012 2:37 AMModerator -
Are there any plans to provide an equivalent of MapVirtualKey\MapVirtualKeyEx in WinRT?Friday, June 1, 2012 2:16 PM