当前位置: 首页 > 知识库问答 >
问题:

我想要一个简单的程序来冻结/解冻输入,当我按下一个键

艾文斌
2023-03-14

这似乎是件很简单的事情,但我在任何地方都找不到。我想要一个简单的程序(比如自动热键,但我找不到使用自动热键的方法),当我按下某个键时,它会冻结我的键盘和鼠标(无论我当时按什么键,即使我释放了实际的键/按钮),并将其冻结,直到我再次按下该键(选择的键从未被其他程序视为按下)。

我只是希望这样,如果游戏希望我按住一些按钮,我可以按下按钮,按下指定的键,松手,然后在我应该松开按钮的时候再次按下键。

共有1个答案

颛孙越
2023-03-14

这在文本编辑器中起作用。但不确定它在游戏中如何工作。

#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
 类似资料: