If 2 or more keys are pressed, disable all Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rex Wrecks
Posts: 2
Joined: 26 Jun 2022, 16:30

If 2 or more keys are pressed, disable all

Post by Rex Wrecks » 26 Jun 2022, 16:33

I don't know exactly how to do this, Iv tried making it on my own, but it always malfunctioned badly.
So I need some help or guidance.
What I need to figure out how to make is a script that if it detects 2 keys or more being pressed at the same time then they all get prevented.
Thanks in advance.

User avatar
mikeyww
Posts: 26598
Joined: 09 Sep 2014, 18:38

Re: If 2 or more keys are pressed, disable all  Topic is solved

Post by mikeyww » 26 Jun 2022, 17:23

There could be some bugs here with upper case.

Code: Select all

list := []
Loop, 0xFF {
 key := GetKeyName(Format("VK{:02X}", 0x100 - A_Index))
 If key not contains Button,Wheel,Shift,Control,Alt
 { list.Push(key)
   Hotkey, $%key%, Combo, On
 }
}
Return

Combo:
pressed = 0
For each, key in list
 pressed += GetKeyState(key, "P")
SendInput % pressed = 1 ? "{" SubStr(A_ThisHotkey, 2) "}" : ""
Return
Well, you didn't say it had to be fast. :)

Code: Select all

pressed := []
Loop, 0xFF {
 key := GetKeyName(Format("VK{:02X}", 0x100 - A_Index))
 If (key > "")
  If key not contains Button,Wheel,Shift,Control,Alt
  { Hotkey, %key%, Down, On
    Hotkey, %key% Up, Up, On
  }
}
Return

Down:
pressed[A_ThisHotkey] := True
SendInput % pressed.Count() = 1 ? "{" A_ThisHotkey "}" : ""
Return

Up:
pressed.Delete(StrSplit(A_ThisHotkey, " ").1)
Return

Code: Select all

pressed = `n
Loop, 0xFF {
 key := GetKeyName(Format("VK{:02X}", 0x100 - A_Index))
 If (key > "")
  If key not contains Button,Wheel,Shift,Control,Alt
  { Hotkey, %key%, Down, On
    Hotkey, %key% Up, Up, On
  }
}
Return

Down:
pressed := StrReplace(pressed, "`n" A_ThisHotkey "`n", "`n") A_ThisHotkey "`n"
StrReplace(SubStr(pressed, 2), "`n",, number)
SendInput % number = 1 ? "{" A_ThisHotkey "}" : ""
Return

Up:
pressed := StrReplace(pressed, "`n" StrSplit(A_ThisHotkey, " ").1 "`n", "`n")
Return

Rex Wrecks
Posts: 2
Joined: 26 Jun 2022, 16:30

Re: If 2 or more keys are pressed, disable all

Post by Rex Wrecks » 27 Jun 2022, 04:05

Thanks alot for the help, have a good day sir!

Post Reply

Return to “Ask for Help (v1)”