Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
803 views
in Technique[技术] by (71.8m points)

autohotkey - Is it possible to trigger 2 hotkeys simultaneously in AHK?

I am trying to simulate mouse movement with my keyboard. I can move in the xy plane one direction at a time but now I need diagonal movement, e.g. holding down shift + w + d moves upright. I would prefer answers that can address the problem of triggering multiple hotkeys simultaneously in general since this is something I would like to implement in other scripts.

#NoEnv
SetWorkingDir %A_ScriptDir%
#SingleInstance Force
#NoTrayIcon
SendMode Input
SetDefaultMouseSpeed, 0

;Variables
taskbar_height := 630
effective_screen_height := A_ScreenHeight - taskbar_height
x_movement := 0.03*A_ScreenWidth
y_movement := 0.05*effective_screen_height

;Mouse
+a::MouseMove, -%x_movement%, 0,, R
+d::MouseMove, %x_movement%, 0,, R
+w::MouseMove, 0, -%y_movement%,, R
+s::MouseMove, 0, %y_movement%,, R

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

(Standard) AutoHotkey does not support multi-threading, but you can use things like SetTimer and other shenanigans for "fake multithreading" (some examples here).

For this specific case, however, it would just be better to have a loop that checks which combination of the critical keys (Shift, w, a, s, and d) are held down and act appropriately based on that.

Note: AutoHotkey_H exists and provides multithreading functionality to vanilla AHK, as well as some other features if you interested in that approach.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...