Hello there.
I'm trying to get function VkKeyScan from user32.dll to work, to avoid making an awkward switch or hashtable to convert keys for other DLL calls.
According to MSDN, function is defined as
short VkKeyScan(TCHAR ch)
My current code is:
func _VkKeyScan($ch)
local $aResult = dllCall('user32.dll', 'short', 'VkKeyScan', 'int', $ch)
if (@error) then
consoleWrite('(debug) Something did not work.')
return setError(@error, @extended, ''
It would be even better to use Unicode (VkKeyScanW, AscW) ConsoleWrite('vkKeyScan for [' & "a" & '] = [' & _vkKeyScan("a") & ']' & @CR)
; return value is VK code
; @extended contains shift state
Func _VkKeyScan($s_Char)
Local $a_Ret = DllCall("user32.dll", "short", "VkKeyScanW", "ushort", AscW($s_Char))
If @error Then Return SetError(@error, @extended, -1)
Return SetExtended(BitShift($a_Ret[0], 8), BitAnd($a_Ret[0], 0xFF))
EndFunc