use of control characters in hotstrings

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Sam_
Posts: 146
Joined: 20 Mar 2014, 20:24

use of control characters in hotstrings

05 Sep 2018, 09:39

As has been done in a variety of ways around the forums in the past, I’d like to make some hotstrings/hotkeys to transform English letters into Greek. The scheme I’d like to use is:

Code: Select all

/*
Dec		Hex		ASCII	Greek	Unicode Hex
97		61		a		α		03B1
98		62		b		β		03B2
99		63		c		χ		03C7
100		64		d		δ		03B4
101		65		e		ε		03B5
102		66		f		φ		03C6
103		67		g		γ		03B3
104		68		h		η		03B7
105		69		i		ι		03B9
106		6A 		j		ϕ		03D5
107		6B 		k		κ		03BA
108		6C 		l		λ		03BB
109		6D 		m		μ		03BC
110		6E 		n		ν		03BD
111		6F 		o		ο		03BF
112		70		p		π		03C0
113		71		q		θ		03B8
114		72		r		ρ		03C1
115		73		s		σ		03C3
116		74		t		τ		03C4
117		75		u		υ		03C5
118		76		v		ϖ		03D6
119		77		w		ω		03C9
120		78		x		ξ		03BE
121		79		y		ψ		03C8
122		7A 		z		ζ		03B6
65		41		A		Α		0391
66		42		B		Β		0392
67		43		C		Χ		03A7
68		44		D		Δ		0394
69		45		E		Ε		0395
70		46		F		Φ		03A6
71		47		G		Γ		0393
72		48		H		Η		0397
73		49		I		Ι		0399
74		4A 		J		ϑ		03D1
75		4B 		K		Κ		039A
76		4C 		L		Λ		039B
77		4D 		M		Μ		039C
78		4E 		N		Ν		039D
79		4F 		O		Ο		039F
80		50		P		Π		03A0
81		51		Q		Θ		0398
82		52		R		Ρ		03A1
83		53		S		Σ		03A3
84		54		T		Τ		03A4
85		55		U		Υ		03A5
86		56		V		ς		03C2
87		57		W		Ω		03A9
88		58		X		Ξ		039E
89		59		Y		Ψ		03A8
90		5A 		Z		Ζ		0396
*/
Unlike other solutions, I’d like to have a hotstrings that consist of the English letter followed by the press of Ctrl and g. Something like :*?C:a{Control down}g{Control up}::{U+03B1}, but since hotstrings don’t seem to support control characters or non-raw keys as the text to replace, this obviously doesn’t work. The best (although admittedly not that good) solution I’ve been able to come up with is:

Code: Select all

^g::
	SendInput, +{Left}
	Sleep, 100
	Clipboard:=""
	SendInput, ^x
	ClipWait, 2
	LastChar:=Clipboard
	If IsLabel(Asc(LastChar))
		GoSub, % Asc(LastChar)
	Else
		SendInput, ^v
Return


97:
	SendInput, {U+03B1}
Return

98:
	SendInput, {U+03B2}
Return

99:
	SendInput, {U+03C7}
Return

100:
	SendInput, {U+03B4}
Return

101:
	SendInput, {U+03B5}
Return

102:
	SendInput, {U+03C6}
Return

103:
	SendInput, {U+03B3}
Return

104:
	SendInput, {U+03B7}
Return

105:
	SendInput, {U+03B9}
Return

106:
	SendInput, {U+03D5}
Return

107:
	SendInput, {U+03BA}
Return

108:
	SendInput, {U+03BB}
Return

109:
	SendInput, {U+03BC}
Return

110:
	SendInput, {U+03BD}
Return

111:
	SendInput, {U+03BF}
Return

112:
	SendInput, {U+03C0}
Return

113:
	SendInput, {U+03B8}
Return

114:
	SendInput, {U+03C1}
Return

115:
	SendInput, {U+03C3}
Return

116:
	SendInput, {U+03C4}
Return

117:
	SendInput, {U+03C5}
Return

118:
	SendInput, {U+03D6}
Return

119:
	SendInput, {U+03C9}
Return

120:
	SendInput, {U+03BE}
Return

121:
	SendInput, {U+03C8}
Return

122:
	SendInput, {U+03B6}
Return

65:
	SendInput, {U+0391}
Return

66:
	SendInput, {U+0392}
Return

67:
	SendInput, {U+03A7}
Return

68:
	SendInput, {U+0394}
Return

69:
	SendInput, {U+0395}
Return

70:
	SendInput, {U+03A6}
Return

71:
	SendInput, {U+0393}
Return

72:
	SendInput, {U+0397}
Return

73:
	SendInput, {U+0399}
Return

74:
	SendInput, {U+03D1}
Return

75:
	SendInput, {U+039A}
Return

76:
	SendInput, {U+039B}
Return

77:
	SendInput, {U+039C}
Return

78:
	SendInput, {U+039D}
Return

79:
	SendInput, {U+039F}
Return

80:
	SendInput, {U+03A0}
Return

81:
	SendInput, {U+0398}
Return

82:
	SendInput, {U+03A1}
Return

83:
	SendInput, {U+03A3}
Return

84:
	SendInput, {U+03A4}
Return

85:
	SendInput, {U+03A5}
Return

86:
	SendInput, {U+03C2}
Return

87:
	SendInput, {U+03A9}
Return

88:
	SendInput, {U+039E}
Return

89:
	SendInput, {U+03A8}
Return

90:
	SendInput, {U+0396}
Return
This works well enough in Notepad, but the results are suboptimal in Word and Excel where I would use these most often. Any suggestions for a better solution would be greatly appreciated.

TIA,
Sam.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: use of control characters in hotstrings

05 Sep 2018, 10:45

results are suboptimal
why, whats wrong with it
Rohwedder
Posts: 7676
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: use of control characters in hotstrings

05 Sep 2018, 11:02

Hallo,
Try it without SendInput, ^x:

Code: Select all

#InstallKeybdHook
~Shift Up::Asc := Asc(A_PriorKey) - 32
~Control::
IF A_PriorHotkey <> ~Shift Up
	Asc:=Asc(A_PriorKey)
Return
^g::ToolTip, % "The Letter was: " Chr(Asc)
Sam_
Posts: 146
Joined: 20 Mar 2014, 20:24

Re: use of control characters in hotstrings

05 Sep 2018, 12:43

swagfag wrote:
results are suboptimal
why, whats wrong with it
In Word, when cutting text all the way back to the beginning of the line, the cursor automatically jumps to the end of the previous line. In Excel, the use of {Left} tends to change which cell has focus, although this behavior varies depending on just how you have focused on a cell to enter text before calling the hotkey. Using a legitimate hotstring doesn't seem to have any of these issues.
Rohwedder wrote:Hallo,
Try it without SendInput, ^x:

Code: Select all

#InstallKeybdHook
~Shift Up::Asc := Asc(A_PriorKey) - 32
~Control::
IF A_PriorHotkey <> ~Shift Up
	Asc:=Asc(A_PriorKey)
Return
^g::ToolTip, % "The Letter was: " Chr(Asc)
I’m getting inconsistent results with this. Sometimes I get the expected letter, sometimes not.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: cinematic6436, mikeyww, Sarhad, sofista, Twisting and 302 guests