What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Get ascii character from virtual key code

Pages: (2): « First [ 1 ] 2 » Last »
Get ascii character from virtual key code
Author: Message:
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
O.P. Get ascii character from virtual key code
In an ChatWndEditKeyDown event, it is sometimes necessary to find which key is down. I could do this by directly comparing the virtual key code that was pressed with the one I would like to see, but this could fail on keyboards with different languages.

What I need is a way to find which character was pressed regardless of the keyboard layout that is fast and won't slow down typing...but I can't figure out how.

If there is a better way to do this please tell me :).

EDIT: Maybe the ToAscii and ToAsciiEx functions could be used, but I don't think the event passes enough information to call them.

This post was edited on 01-15-2007 at 08:19 PM by deAd.
01-15-2007 08:18 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Get ascii character from virtual key code
It is doable using ToAcii, GetKeyboardState, GetKeyboardLayout.
01-15-2007 08:45 PM
Profile E-Mail PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
O.P. RE: Get ascii character from virtual key code
But will it slow down typing and is there a better way?
01-15-2007 08:47 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Get ascii character from virtual key code
quote:
Originally posted by deAd
...but this could fail on keyboards with different languages.
it isn't 'language' (better: 'keyboard') specific...

What you are referring to are keyboard scancodes which do depend on the keyboard layout, but virtual keycodes (like used in ChatWndEditKeyDown) don't...

search... : "CookieRevised's reply to # key and = key" ;)

This post was edited on 01-15-2007 at 09:04 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-15-2007 09:00 PM
Profile PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
O.P. RE: Get ascii character from virtual key code
So according to your post, every character has a designated virtual key code and it's safe to compare the key code from the event to the one I want without discrepancies?

EDIT: MSDN says "Used for miscellaneous characters; it can vary by keyboard." and that it's the one I'm looking for on the US standard keyboard...this contradicts what you're saying, no?

This post was edited on 01-15-2007 at 09:10 PM by deAd.
01-15-2007 09:07 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Get ascii character from virtual key code
quote:
Originally posted by deAd
So according to your post, every character has a designated virtual key code and it's safe to compare the key code from the event to the one I want without discrepancies?
yes, since every character on your keyboard has a virtual key code (which is the same for everybody).

Note: but not every key code has a character assigned to it, eg: the CTRL key will only have a virtual key code (which is the same for everybody), while the "A" key has both a virtual key code as a character code.

PS: logically, it would have been very doubtfull Patchou would include a function like that which would highly depend on keyboard layout (making it virtually impossible to use such a function to catch keystrokes in scripts)

;)

quote:
Originally posted by deAd
EDIT: MSDN says "Used for miscellaneous characters; it can vary by keyboard." and that it's the one I'm looking for on the US standard keyboard...this contradicts what you're saying, no?
No, that is either about Keyboard SCAN codes...

...Or either about the fact that a keyboard can contain special keys which can be defined by the manufacters. In those few cases, those keys are extremely off standard and should never be used to control a program made for public use. (eg: the VK_OEM_x keys are examples of such keys. The OEM says it all, Original Equipment Manufacturer)

See my linked-to post in the first reply and also "CookieRevised's reply to Virtual Key Code".

This post was edited on 01-15-2007 at 09:23 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-15-2007 09:10 PM
Profile PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
O.P. RE: Get ascii character from virtual key code
The keycode I am using is a VK_OEM_x code. So in this case it won't be guaranteed to turn out the right key?
01-15-2007 09:26 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Get ascii character from virtual key code
quote:
Originally posted by deAd
The keycode I am using is a VK_OEM_x code. So in this case it won't be guaranteed to turn out the right key?
yep, indeed...

If you're going to use that script for your own, then it's ok. But don't publish it for others to use since those keys might not even be on the user's keyboard.

This post was edited on 01-15-2007 at 09:43 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-15-2007 09:43 PM
Profile PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
O.P. RE: RE: Get ascii character from virtual key code
quote:
Originally posted by CookieRevised
quote:
Originally posted by deAd
The keycode I am using is a VK_OEM_x code. So in this case it won't be guaranteed to turn out the right key?
yep, indeed...

If you're going to use that script for your own, then it's ok. But don't publish it for others to use since those keys might not even be on the user's keyboard.

I am probably going to publish it but I could remove this feature.

I think I have fixed the problem by comparing the key code with the result of VkKeyScanW and the character's ASCII code :)

EDIT: and it's not a very uncommon key.... I'm fairly certain almost all keyboards have it, as it's used within plus! as well :P

This post was edited on 01-15-2007 at 09:45 PM by deAd.
01-15-2007 09:44 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: RE: Get ascii character from virtual key code
quote:
Originally posted by deAd
I think I have fixed the problem by comparing the key code with the result of VkKeyScanW and the character's ASCII code :)
No...

And since you speak of "the character's ASCII code", it means that this special key of yours might just be a shortcut of another standard existing key. So, use that one instead.

quote:
Originally posted by deAd
EDIT: and it's not a very uncommon key.... I'm fairly certain almost all keyboards have it, as it's used within plus! as well :P
tbh, very very doubtfull.

-------

What is the key and what is it supposed todo in Plus!?
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-15-2007 10:01 PM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On