GetKeyName is most definitely entirely dependent on the keyboard layout for single-character key names. If the VK is not between A (vk41) and Z (vk5A), it uses
MapVirtualKeyEx to retrieve the corresponding character, according to the keyboard layout. For the A - Z keys (which MapVirtualKeyEx always maps to those ASCII letters), it instead uses
ToUnicodeEx to translate the VK to a character according to the keyboard layout.
However, GetKeyName uses
the script's current keyboard layout. Depending on the OS and settings, changing your keyboard layout might not affect the script, particularly if the script doesn't have an active window. Doing something like showing a MsgBox or ListLines prior to calling GetKeyName may affect the result.
Even so, if I switch to a Farsi keyboard layout and run the following script, I don't see any English letters (in the message text):
Code: Select all
Loop 255
if StrLen(k := GetKeyName(Format("vk{:x}",A_Index))) = 1
s .= k
MsgBox s
EndKey uses the same method of translation, dependent on the script's keyboard layout at the time you retrieve its value. As far as I can tell, your script similarly returns only Farsi letters if that keyboard layout is active.