这看起来很简单的事情,但我却找不到它。我想要一个简单的程序(例如 AutoHotkey,但我找不到使用 AutoHotkey 来实现这一点的方法),它将冻结我的键盘和鼠标(无论我当时按下的是什么,即使我释放了实际的键,也会一直按下) /按钮)当我按下某个键时,并保持冻结状态,直到我再次按下该键(所选键永远不会被认为被其他程序按下)。
我只是想要这样,如果游戏需要我按住某些按钮,我可以按下按钮,按下指定的键,放开,然后在我应该释放按钮时再次按下该键。
这适用于文本编辑器。但不确定它在游戏中如何运作。
#NoEnv
#Warn
#SingleInstance Force
#UseHook
SetWorkingDir %A_ScriptDir%
SendMode Input
Global isHold := false ; Alternates between "true" and "false" at each "LShift" press.
; Hotkey below will only be active if the game's window is active
#IfWinActive "PutYourGameWindowTitleHere"
; Sends {LShift Down} if isHold == false, {LShift Up} if isHold == true
; Asterisk means it will work even if other keys are held at the same time.
*LShift::Send % (isHold := !isHold) ? "{LShift Down}" : "{LShift Up}"
#IfWinActive
更新:同样,您必须自己在游戏中测试这一点。
#NoEnv
#Warn
#SingleInstance Force
#UseHook
SetWorkingDir %A_ScriptDir%
SendMode Input
Global aKeysToFreeze := { LShift: false, a: false }, isFreezeOn := false
`::fToggleFreeze()
^`:: ; You can use this to check the logical state of the key
If GetKeyState("a")
msgbox Key is pressed.
else msgbox Key is not pressed.
return
fToggleFreeze() {
Local
Global aKeysToFreeze, isFreezeOn
If isFreezeOn { ; If there are frozen keys,
For sKeyName, isKeyFrozen in aKeysToFreeze {
Send % "{" sKeyName " Up}" ; send key up event for each key and
aKeysToFreeze[sKeyName] := false ; set the each key's frozen state to false
}
} else {
For sKeyName, isKeyFrozen in aKeysToFreeze
If GetKeyState(sKeyName, "P") ; If the key is physically pressed
aKeysToFreeze[sKeyName] := true ; set frozen state to true
}
isFreezeOn := !isFreezeOn ; Frozen mode toggle
}
*a::Send {Blind}{a DownR}
*LShift:: Send {Blind}{LShift DownR}
#If !aKeysToFreeze["a"] ; If the key is frozen, the key up hotkey is blocked
*a Up::Send {Blind}{a Up}
#If !aKeysToFreeze["LShift"]
*LShift Up::Send {Blind}{LShift Up}
#If
这个怎么样:
; Start Notepad
If !WinExist("ahk_class Notepad")
Run Notepad
WinWait, ahk_class Notepad
WinActivate
; Send a key to Notepad every 3 seconds, if Notepad is active
Loop
{
WinWaitActive, ahk_class Notepad
SendInput, a
Sleep, 3000
}
; Press F1 to freeze keyboard and mouse
; the script continues sending the key
F1::
BlockInput On
UnBlock := true ; assign the boolean value "true" to this variable
return
; Press F2 to unfreeze keyboard and mouse
#If UnBlock ; if this variable has the value "true"
F2::
UnBlock := false
BlockInput Off
return
#If