proof of concept: Send what you mean

Post your working scripts, libraries and tools
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

proof of concept: Send what you mean

26 Nov 2017, 19:40

- The idea behind this script is for something like SendInput, ^v to work the same way, regardless of the keyboard layout. Or more specifically, it will work based on the array specified in the function, by converting parts of the string to something else.
- You may also be able to choose a different array to refer to based on what the current keyboard layout is. Do an Internet search for: AutoHotkey GetKeyboardLayout.

Code: Select all

q::
vKeys := "^v"
;vKeys := "^c"
SendEx(vKeys)
return

SendEx(vKeys)
{
	;static oArray := Object("v","{vk56}", "w","{U+63}")
	;static oArray := Object("v","{vk56}")
	;static oArray := Object("v","{U+76}")

	static oArray := {}, vIsInit
	if !vIsInit
	{
		Loop, 26
			oArray[Chr(96+A_Index)] := "{vk" Format("{:X}", 0x40+A_Index) "}"
		vIsInit := 1
	}

	Loop, 3
		vUnused%A_Index% := Chr(A_Index)
	vKeys := StrReplace(vKeys, "{{}", "{" vUnused1 "}")
	vKeys := StrReplace(vKeys, "{}}", "{" vUnused2 "}")
	vKeys := StrReplace(vKeys, "{", "{" vUnused3)
	vKeys := StrReplace(vKeys, "}", "}" vUnused3)
	vOutput := ""
	Loop, Parse, vKeys, % vUnused3
	{
		vTemp := A_LoopField
		if (SubStr(vTemp, 1, 1) = "{")
		{
			vOutput .= vTemp
			continue
		}
		Loop, Parse, vTemp
		{
			vChar := A_LoopField
			if oArray.HasKey(vChar)
				vOutput .= oArray[vChar]
			else
				vOutput .= vChar
		}
	}
	vOutput := StrReplace(vOutput, "{" vUnused1 "}", "{{}")
	vOutput := StrReplace(vOutput, "{" vUnused2 "}", "{}}")
	vOutput := StrReplace(vOutput, vUnused3)
	;MsgBox, % vOutput
	SendInput, % vOutput
}
Last edited by jeeswg on 30 Jan 2018, 23:20, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: proof of concept: Send what you mean

30 Jan 2018, 23:10

- The function was in response to the first thread, and relates to the second:
Bug in Send Command - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 01#p185001
Send problems with VK/SC codes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 19#p190319

- The function was more or less made redundant by this update:
v1.1.27 - It must be Christmas - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 24&t=41831
Changed a-z to mean vk41-vk5A when absent from the keyboard layout, except with Raw mode or when sending single unmodified characters. This allows hotkeys and sent keyboard shortcuts to work more intuitively on certain non-English keyboard layouts.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Scripts and Functions”

Who is online

Users browsing this forum: JBensimon, KruschenZ, TAC109 and 19 guests