-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamelToSnake.ahk
74 lines (68 loc) · 1.74 KB
/
CamelToSnake.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#InstallKeybdHook
#SingleInstance
#NoEnv
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
lowers := ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
global camelString :=
global snake_string :=
; camelLength = 0
for i,v in lowers
{
Hotkey, ~%v%, captureCamel
Hotkey, ~+%v%, captureCamel
}
Hotstring(":: ", " ") ; for whatever reason, dummy setting a hotstring is necessary to get this to work for the first letter of the first dynamic hotstring
Hotstring("Reset")
ResetConvertCamelSnake()
+F7::Reload ; Hotstring command throws error without this
ResetConvertCamelSnake()
{
camelString :=
snake_string :=
return
}
captureCamel:
{
capsOn := GetKeyState("CapsLock","T")
shiftDn := StrLen(A_ThisHotkey) > 2
lowerLetter := SubStr(A_ThisHotkey, StrLen(A_ThisHotkey), 1)
upperLetter := Chr(Asc(lowerLetter) - 32)
If capsOn ^ shiftDn
{
if StrLen(camelString) > 0
{
snake_string := snake_string "_" lowerLetter
}
Else
{
snake_string := snake_string upperLetter
}
camelString := camelString upperLetter
}
Else
{
camelString := camelString lowerLetter
snake_string := snake_string lowerLetter
}
Hotstring("::" camelString, snake_string)
return
}
~LButton::
~RButton::
~Left::
~Right::
~Up::
~Down::
~Enter::
~Tab::
~Space::
{
; camelLength := StrLen(camelString)
; Send {Backspace %camelLength%}{BackSpace}
; Send % snake_string
; Send {Space}
Hotstring("Reset")
ResetConvertCamelSnake()
return
}