Skip to content

Commit 2d89a42

Browse files
committed
Refactor the code to implement the functionality in a more logical way.
1 parent e3cb7a6 commit 2d89a42

File tree

2 files changed

+153
-144
lines changed

2 files changed

+153
-144
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Features
66

7-
- Use right button to move canvas instead of right button.
7+
- Use right button to move canvas instead of middle button.
88
- Hold alt on edge with left click to remove it.
99
- [Shader Graph Variables](https://github.com/Cyanilux/ShaderGraphVariables) are supported.
1010

@@ -22,8 +22,7 @@
2222

2323
### Known Issues :
2424

25-
- The A, O and F keys can only be inputted when the mouse icon is I Beam.
26-
- Ctrl 0 1 and 2 will not work.
25+
- The A, O and F keys can only be entered when the mouse icon is I Beam or when the mouse is located near the input state.
2726

2827
## Shortcut Keys:
2928

ShaderGraphHelper.ahk

+151-141
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
22
#SingleInstance, force
3+
#InstallKeybdHook
34
#InstallMouseHook
45
AutoTrim, Off
56
CoordMode, Mouse, Screen
@@ -10,7 +11,7 @@ SetBatchLines -1
1011
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
1112
DetectHiddenText, On
1213

13-
ver:="0.2.0"
14+
ver:="0.3.0"
1415
nodesPath=%A_ScriptDir%\Nodes
1516

1617
; 托盘菜单
@@ -32,137 +33,79 @@ else
3233
}
3334
return
3435

35-
UpdateScrit:
36-
Run, https://github.com/millionart/UnityShaderGraphHelper/releases
37-
Return
38-
3936
#IfWinActive, ahk_class UnityContainerWndClass
4037

38+
LButton::
39+
TryGetAnyKey()
40+
Return
41+
4142
; Block GraphView stupid Shourtcuts
4243

4344
$a::BlockSend("a")
44-
Return
45-
46-
$o::BlockSend("o")
47-
Return
48-
49-
$f::BlockSend("f")
50-
Return
51-
52-
RButton::
53-
if WinExist("A")
54-
ControlGetFocus, curCtrl
55-
56-
ControlGetText, ctrlTxt, %curCtrl%
57-
if ctrlTxt=UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow
58-
{
59-
MouseGetPos, perPosX, perPosY
60-
Send, {MButton Down}
61-
KeyWait, RButton ,
62-
HookRightMouse(perPosX,perPosY)
63-
}
64-
Else
65-
{
66-
Send, {RButton Down}
67-
KeyWait, RButton
68-
Send, {RButton Up}
69-
}
70-
Return
71-
72-
$!LButton::
73-
if WinExist("A")
74-
ControlGetFocus, curCtrl
75-
ControlGetText, ctrlTxt, %curCtrl%
76-
if ctrlTxt=UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow
77-
{
78-
MouseGetPos, perPosX, perPosY
79-
Send, {LButton Down}
80-
MouseMove, perPosX, perPosY+20,0
81-
MouseMove, perPosX, perPosY,0
82-
Send, {LButton Up}
83-
Sleep, 80
84-
Send, {Escape}
85-
}
86-
Else
87-
{
88-
Send, !{LButton Down}
89-
KeyWait, LButton
90-
Send, !{LButton Up}
91-
}
92-
Return
93-
94-
0 & LButton::CreateNode("Integer")
95-
Return
96-
97-
1 & LButton::CreateNode("Float")
98-
Return
99-
100-
2 & LButton::CreateNode("Vector2")
101-
Return
102-
103-
~3 & LButton::CreateNode("Vector3")
104-
Return
105-
106-
~4 & LButton::CreateNode("Vector4")
107-
Return
108-
109-
~5 & LButton::CreateNode("Color")
110-
Return
111-
112-
~B & LButton::CreateNode("Split")
113-
Return
114-
115-
~V & LButton::CreateNode("Combine")
116-
Return
117-
118-
; https://github.com/Cyanilux/ShaderGraphVariables
119-
~G & LButton::CreateNode("GetVariable")
120-
Return
45+
Return
12146

122-
; https://github.com/Cyanilux/ShaderGraphVariables
123-
~R & LButton::CreateNode("RegisterVariable")
124-
Return
125-
126-
~K & LButton::CreateNode("ChannelMask")
127-
Return
47+
$o::BlockSend("o")
48+
Return
12849

129-
~X & LButton::CreateNode("Cross")
130-
Return
50+
$f::BlockSend("f")
51+
Return
13152

132-
~. & LButton::CreateNode("DotProduct")
133-
Return
134-
135-
~L & LButton::CreateNode("Lerp")
136-
Return
137-
138-
~N & LButton::CreateNode("Normalize")
139-
Return
140-
141-
~O & LButton::CreateNode("OneMinus")
142-
Return
143-
144-
~P & LButton::CreateNode("Power")
145-
Return
53+
RButton::
54+
if WinExist("A")
55+
ControlGetFocus, curCtrl
14656

147-
~A & LButton::CreateNode("Add")
148-
Return
57+
ControlGetText, ctrlTxt, %curCtrl%
58+
if ctrlTxt=UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow
59+
{
60+
MouseGetPos, perPosX, perPosY
61+
Send, {MButton Down}
62+
KeyWait, RButton ,
63+
HookRightMouse(perPosX,perPosY)
64+
}
65+
Else
66+
{
67+
Send, {RButton Down}
68+
KeyWait, RButton
69+
Send, {RButton Up}
70+
}
71+
Return
14972

150-
~D & LButton::CreateNode("Divide")
151-
Return
73+
$!LButton::
74+
if WinExist("A")
75+
ControlGetFocus, curCtrl
15276

153-
~M & LButton::CreateNode("Multiply")
154-
Return
77+
ControlGetText, ctrlTxt, %curCtrl%
78+
if ctrlTxt=UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow
79+
{
80+
MouseGetPos, perPosX, perPosY
81+
Send, {LButton Down}
82+
MouseMove, perPosX, perPosY+40,0
83+
MouseMove, perPosX, perPosY,0
84+
Send, {LButton Up}
85+
Sleep, 100
86+
Send, {Escape}
87+
}
88+
Else
89+
{
90+
Send, !{LButton Down}
91+
KeyWait, LButton
92+
Send, !{LButton Up}
93+
}
94+
Return
15595

156-
~S & LButton::CreateNode("Subtract")
157-
Return
96+
#IfWinActive
15897

159-
~T & LButton::CreateNode("SampleTexture2D")
98+
ExitScrit:
99+
ExitApp
160100
Return
161101

162-
~U & LButton::CreateNode("TillingAndOffset")
102+
UpdateScrit:
103+
Run, https://github.com/millionart/UnityShaderGraphHelper/releases
163104
Return
164105

165-
#IfWinActive
106+
RemoveToolTip:
107+
ToolTip
108+
return
166109

167110
HookRightMouse(perPosX,perPosY)
168111
{
@@ -173,7 +116,7 @@ HookRightMouse(perPosX,perPosY)
173116
moveX:=abs(curPosX-perPosX)
174117
moveY:=abs(curPosY-perPosY)
175118

176-
; 如果X大于10,Y大于10, 在当前坐标弹出界面
119+
; 如果X大于10,Y大于10, 则认为是右键移动
177120
If (moveX>10) || (moveY>10)
178121
{
179122
Send, {MButton Up}
@@ -193,47 +136,114 @@ BlockSend(key)
193136
ControlGetText, ctrlTxt, %curCtrl%
194137
if ctrlTxt=UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow
195138
{
196-
If (A_Cursor!="IBeam")
139+
MouseGetPos, MouseX, MouseY
140+
PixelGetColor, color, %MouseX%, %MouseY%
141+
142+
If (A_Cursor="IBeam" || (color!="0x202020" && color!="0x1F1F1F" && color!="0x393939" && color!="0xAEAEAE" && color!="0x4B92F3" && color!="0xCB3022" && color!="0xF6FF9A"))
197143
{
198-
Return
144+
while GetKeyState(key, "P")
145+
{
146+
Send, {%key%}
147+
sleep, Max(400 - A_Index*100, 50)
148+
}
199149
}
200150
else
201151
{
202-
SendInput, %key%
152+
global blockedKeyInput:=key
153+
KeyWait, %key%
154+
global blockedKeyInput:=""
155+
Return
203156
}
204157
}
205158
else
206159
{
207-
Send, {%key% Down}
208-
KeyWait, %key%
209-
Send, {%key% Up}
160+
while GetKeyState(key, "P")
161+
{
162+
Send, {%key%}
163+
sleep, Max(400 - A_Index*100, 50)
164+
}
210165
}
211166
}
212167

213-
ExitScrit:
214-
ExitApp
215-
Return
216-
217-
CreateNode(nodeName)
168+
TryGetAnyKey()
218169
{
219170
if WinExist("A")
220171
ControlGetFocus, curCtrl
221172
ControlGetText, ctrlTxt, %curCtrl%
222173
if ctrlTxt=UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow
223174
{
224-
global nodesPath
225-
clipSaved:=ClipBoardAll
226-
FileRead, nodeclip, %nodesPath%\%nodeName%.txt
227-
Clipboard:=nodeclip
228-
ClipWait 0.2, 1
229-
; WinMenuSelectItem is lag, don't use it
230-
;;;;; WinMenuSelectItem, A,, Edit, Paste
231-
Send, {CtrlDown}v
232-
Sleep, 10
233-
Send, {CtrlUp}
234-
Sleep, 10
235-
Clipboard:=clipSaved
236-
ClipWait 0.1, 1
237-
; MsgBox, %nodesPath% | %fileName% | %nodeclip%
175+
global blockedKeyInput
176+
177+
InputHook :=A_PriorKey
178+
; InputHook := Format(Upper , %InputHook)
179+
StringUpper, InputHook, InputHook
180+
; ToolTip, %InputHook%
181+
If GetKeyState(A_PriorKey) || blockedKeyInput!=""
182+
{
183+
Switch blockedKeyInput
184+
{
185+
Case "a": InputHook:="A"
186+
Case "o": InputHook:="O"
187+
Case "f": InputHook:="F"
188+
}
189+
190+
Switch InputHook
191+
{
192+
Case "0": CreateNode("Integer")
193+
Case "1": CreateNode("Float")
194+
Case "2": CreateNode("Vector2")
195+
Case "3": CreateNode("Vector3")
196+
Case "4": CreateNode("Vector4")
197+
Case "5": CreateNode("Color")
198+
Case "B": CreateNode("Split")
199+
Case "V": CreateNode("Combine")
200+
Case "G": CreateNode("GetVariable") ; https://github.com/Cyanilux/ShaderGraphVariables
201+
Case "R": CreateNode("RegisterVariable") ; https://github.com/Cyanilux/ShaderGraphVariables
202+
Case "K": CreateNode("ChannelMask")
203+
Case "X": CreateNode("Cross")
204+
Case ".": CreateNode("DotProduct")
205+
Case "L": CreateNode("Lerp")
206+
Case "N": CreateNode("Normalize")
207+
Case "O": CreateNode("OneMinus")
208+
Case "E": CreateNode("Power")
209+
Case "A": CreateNode("Add")
210+
Case "D": CreateNode("Divide")
211+
Case "M": CreateNode("Multiply")
212+
Case "S": CreateNode("Subtract")
213+
Case "T": CreateNode("SampleTexture2D")
214+
Case "U": CreateNode("TillingAndOffset")
215+
; Default:
216+
; ToolTip, %A_Time%
217+
; SetTimer, RemoveToolTip, 1000
218+
}
219+
}
238220
}
221+
Send, {LButton Down}
222+
KeyWait, LButton
223+
Send, {LButton Up}
224+
}
225+
226+
CreateNode(nodeName)
227+
{
228+
global nodesPath
229+
clipSaved:=ClipBoardAll
230+
FileRead, nodeclip, %nodesPath%\%nodeName%.txt
231+
Clipboard:=nodeclip
232+
ClipWait 0.1, 1
233+
; WinMenuSelectItem is lag, don't use it
234+
; WinMenuSelectItem, A,, Edit, Paste
235+
; https://www.the-automator.com/pasting-with-sendmessage-in-autohotkey/
236+
; Not work
237+
; ControlGetFocus, vCtlClassNN, A
238+
; ControlGet, hCtl, Hwnd,, % vCtlClassNN, A
239+
; SendMessage, 0x0302,,,, % “ahk_id ” hCtl ;WM_PASTE := 0x302
240+
241+
Send, {%key% Up}^{v}
242+
Sleep, 10
243+
Send, {Ctrl Up}
244+
; BlockInput Off
245+
Sleep, 10
246+
Clipboard:=clipSaved
247+
ClipWait 0.1, 1
248+
; MsgBox, %nodesPath% | %fileName% | %nodeclip%
239249
}

0 commit comments

Comments
 (0)