Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

English Keys=>Virtual Keys


  • Please log in to reply
4 replies to this topic
THRONE
  • Guests
  • Last active:
  • Joined: --
Hi! I need some converter so users can write in ini file original keys like q, w,e,r, etc. And my prog reads it as virtual (like vk51, vk57)

I can do it with ~36+ ifs but mb there is better solution

YMP
  • Members
  • 424 posts
  • Last active: Apr 05 2012 01:18 AM
  • Joined: 23 Dec 2006
For English only characters this should be OK, I think:
Char = N

VK := CharToVk(Char)

If VK
    MsgBox, %VK%
Else
    MsgBox, Invalid character.


; ---------- Function -----------

CharToVk(Char)
{
    VK := DllCall("VkKeyScan", "uchar", Asc(Char), "Short")
    If (VK = -1)
        Return
    SetFormat, Integer, H
    VK :=  SubStr(VK & 0xFF, 3)
    StringUpper, VK, VK
    SetFormat, Integer, D
    Return "vk" VK
}


THRONE
  • Guests
  • Last active:
  • Joined: --
thanks dude! I will use it unless find the way to work my snippet.

THRONE
  • Guests
  • Last active:
  • Joined: --
and what about when the key is not just N but !N (alt+n)?/

YMP
  • Members
  • 424 posts
  • Last active: Apr 05 2012 01:18 AM
  • Joined: 23 Dec 2006
What do you mean by "what"? Alt is a modifier, it shouldn't be converted into a VK code.