Get sc key code always for English keyboard

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Tvlao
Posts: 13
Joined: 29 Jun 2023, 03:39

Get sc key code always for English keyboard

14 Apr 2024, 13:27

This code does not always print the same values for the / key.
If the keyboard is English, it prints one thing, if it is another, it prints something else.

Code: Select all

key := "/"

scKey := GetKeySC(key)
if(scKey){
    scKey := Format("sc{:X}", scKey)
}else{
    scKey := key
}

MsgBox scKey
Need to get always the same value, only for the English keyboard.
teadrinker
Posts: 4335
Joined: 29 Mar 2015, 09:41
Contact:

Re: Get sc key code always for English keyboard

14 Apr 2024, 16:29

Code: Select all

key := "/"
if key = "/" {
    scKey := "sc35"
}
MsgBox scKey
ntepa
Posts: 429
Joined: 19 Oct 2022, 20:52

Re: Get sc key code always for English keyboard

14 Apr 2024, 19:03

Try this:

Code: Select all

MsgBox "current language: " Format("sc{:x}", GetKeySC("/"))
MsgBox "english: " Format("sc{:x}", GetKeySCFromLang("/"))

; Get SC key for keyboard layout, default is english.
GetKeySCFromLang(key, langID := 0x4090409) {
    currentLayout := DllCall("GetKeyboardLayout", "uint", 0)            ; Save previous layout
    DllCall("ActivateKeyboardLayout", "uptr", langID, "uint", 0)        ; Set new keyboard layout
    SC := GetKeySC(key)                                                 ; Get SC for new layout
    DllCall("ActivateKeyboardLayout", "uptr", currentLayout, "uint", 0) ; revert to previous layout
    return SC
}
teadrinker
Posts: 4335
Joined: 29 Mar 2015, 09:41
Contact:

Re: Get sc key code always for English keyboard

14 Apr 2024, 20:24

@ntepa
Wouldn't it be easier to list all the keys you need? ;)

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: jaccotjuhhh, lukepker, mikeyww, sanmaodo and 67 guests