Page 1 of 2

Disable all keyboard buttons

Posted: 01 Jul 2017, 14:04
by RunarSF
This is a simple script that disables all keyboard buttons except escape. To end the script, simply press escape and a message box will pop up.
What might be the use for this script? Personally, I used it when I was cleaning my keyboard and had to remove all the keys, so I wouldn't mess up my computer by spamming random buttons (I know, I know, I could have turned off my computer, but who has time for that.) but you are free to use the script as you wish.

Download: https://pastebin.com/XMrPp1LG
or download the file directly (attatched file) :D

Re: Disable all keyboard buttons

Posted: 04 Jul 2017, 16:51
by feiyue
Good idea! :thumbup:
Your ideas can be succinctly implemented: :D

Code: Select all

hk(f=0) {  ; By FeiYue
  static allkeys, ExcludeKeys:="LButton,RButton"
  if !allkeys
  {
    s:="||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
    Loop, 254
      k:=GetKeyName(Format("VK{:02X}",A_Index))
        , s.=InStr(s, "|" k "|") ? "" : k "|"
    For k,v in {Control:"Ctrl",Escape:"Esc"}
      s:=StrReplace(s, k, v)
    allkeys:=Trim(s, "|")
  }
  ;------------------
  f:=f ? "On":"Off"
  For k,v in StrSplit(allkeys,"|")
    if v not in %ExcludeKeys%
      Hotkey, *%v%, Block_Input, %f% UseErrorLevel
  Block_Input:
  Return
}

hk(1)  ; Disable all keyboard buttons
Sleep, 8000
hk(0)  ; Enable all keyboard buttons
Return

Re: Disable all keyboard buttons

Posted: 05 Jul 2017, 06:14
by SpeedMaster
Nice script. Very useful for keeping children away from the keyboard. I added an option to disable the mouse as well.
Now, I try to implement the ability to display a message something like a reminder on how to unlock.
So far the result is not bad. Any suggestion on how to improve further the function ? :bravo:

Code: Select all

hk(f=0, mouse=0, message:="Keyboard or mouse Locked ! `nPress Alt+F2 to unlock") { 
  static allkeys, ExcludeKeys:="LButton,RButton"
  if !allkeys
  {
     s:="||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
    Loop, 254
      k:=GetKeyName(Format("VK{:0X}",A_Index))
        , s.=InStr(s, "|" k "|") ? "" : k "|"
    For k,v in {Control:"Ctrl",Escape:"Esc"}
      s:=StrReplace(s, k, v)
    allkeys:=Trim(s, "|")
  }
  ;------------------
  f:=f ? "On":"Off"
  if mouse
  ExcludeKeys:=""
  For k,v in StrSplit(allkeys,"|")
    if v not in %ExcludeKeys%
      Hotkey, *%v%, Block_Input, %f% UseErrorLevel
  Block_Input:
  if message!=
  Progress, B1 M fs12 ZH0, %message%
  if (f="off")
  Progress, Off
  Return
}


!F1::
hk(1,1)  ; Disable all keyboard or mouse buttons
return

!F2::
hk(0)  ; Enable all keyboard and mouse buttons
Return



Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 03:01
by iPhilip
Here is a version that allows keyboard keys and/or mouse buttons to be disabled:

Code: Select all

hk(keyboard:=0, mouse:=0, message:="", timeout:=3) { 
   static AllKeys
   if !AllKeys {
      s := "||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
      Loop, 254
         k := GetKeyName(Format("VK{:0X}", A_Index))
       , s .= InStr(s, "|" k "|") ? "" : k "|"
      For k,v in {Control:"Ctrl",Escape:"Esc"}
         AllKeys := StrReplace(s, k, v)
      AllKeys := StrSplit(Trim(AllKeys, "|"), "|")
   }
   ;------------------
   For k,v in AllKeys {
      IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
      Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
   }
   if (message != "") {
      Progress, B1 M FS12 ZH0, %message%
      SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
   Block_Input:
   Return
   TimeoutTimer:
   Progress, Off
   Return
}

!F1::hk(1,1,"Keyboard keys and mouse buttons disabled!`nPress Alt+F2 to enable")   ; Disable all keyboard keys and mouse buttons
!F2::hk(0,0,"Keyboard keys and mouse buttons restored!")         ; Enable all keyboard keys and mouse buttons
!F3::hk(1,0,"Keyboard keys disabled!`nPress Alt+F2 to enable")   ; Disable all keyboard keys (but not mouse buttons)
!F4::hk(0,1,"Mouse buttons disabled!`nPress Alt+F2 to enable")   ; Disable all mouse buttons (but not keyboard keys)
Cheers!

Edit: Added a timeout parameter to the function and changed the default values of the other parameters.

Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 05:46
by SpeedMaster
Thanks a lot iPhilip you did a fantastic job :thumbup: .
Hoever i think the function need to be more tweaked. Suppose you want your child to watch a cartoon or a movie. The permanant display of a message will compromise everything ! :(
It would have more sense to only display the message when typing en hide it after 2 or 3 seconds. :roll:
i was trying to implement that behaviour and also the possibility to disable only the right mouse button (if mouse=2...) but i did not succeed to disble mouse only without the keyboard. Can you implement that in your funtion ? Then it would be perfect. 8-)

here is my attempt
(hide the message after 2 sec and possiblity to lock only the ritght mouse button)

Code: Select all

hk(f=0, mouse=0, message:="") { 
  static allkeys, ExcludeKeys:="LButton,RButton", m
  m:=message
  if !allkeys
  {
     s:="||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
    Loop, 254
      k:=GetKeyName(Format("VK{:0X}",A_Index))
        , s.=InStr(s, "|" k "|") ? "" : k "|"
    For k,v in {Control:"Ctrl",Escape:"Esc"}
      s:=StrReplace(s, k, v)
    allkeys:=Trim(s, "|")
  }
  ;------------------
  f:=f ? "On":"Off"
  if mouse=1                 ;disable all mouse buttons
  ExcludeKeys:=""
  if mouse=2                 ;disable right mouse only
  ExcludeKeys:="LButton"

  For k,v in StrSplit(allkeys,"|")
    if v not in %ExcludeKeys%
      Hotkey, *%v%, Block_Input, %f% UseErrorLevel
  Block_Input:
  if m!=
  Progress, B1 M fs12 ZH0, %m%
  sleep, 1500                ;hide message after 1.5 sec
  f=off
  if (f="off")
  Progress, Off
  Return
}


!F1::
hk(1,2,"Keyboard and right mouse button Locked ! `nPress Alt+F2 to unlock")  ; Disable all keyboard and right mouse buttons
return

!F2::
hk(0,0,"Keyboard and mouse unlocked")  ; Enable all keyboard and mouse buttons
Return




Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 07:32
by wolf_II
Here is a version, that facilitates readability, because I need this bigly :). Thanks to feiyue for your code :thumbup:, sorry about my edits :(.

This code does not treat mouse buttons differently from keyboard keys. This code only uses one "default" message, stored in a super-global variable.
To clarify: It is not meant to address SpeedMaster's requirements, it is meant to be readable (sorry).

@ SpeedMaster: Test my version if you like. You can always change (or request changes) to meet your requirements. At the moment I don't understand why you would need to have mouse buttons treated differently.

Code: Select all

global AllKeys := get_AllKeys()
global Message := "Keyboard and mouse are locked!`nPress Alt+F2 to unlock."
Return ; end of auto-execute section


!F1:: Disable_Keys(True)    ; disable keys
!F2:: Disable_Keys(False)   ; enable keys



;-------------------------------------------------------------------------------
get_AllKeys() { ; return a pipe delimited list of all keys
;-------------------------------------------------------------------------------
    Keys := "NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins"

    Loop, 254
        If KeyName := GetKeyName(Format("VK{:X}", A_Index))
            Keys .= "|" KeyName

    For key, val in {Control: "Ctrl", Escape: "Esc"}
        Keys := StrReplace(Keys, key, val)

    Return, Keys
}



;-------------------------------------------------------------------------------
Disable_Keys(BOOL := False) { ; (en/dis) -able all keys
;-------------------------------------------------------------------------------
    global Block := BOOL ? "On" : "Off"

    For each, KeyName in StrSplit(AllKeys, "|")
        Hotkey, *%KeyName%, Block_Input, %Block% UseErrorLevel

    Block_Input:
        If (Block = "On") {
            Progress, B1 ZH0, %Message%
            Sleep, 2000
            Progress, Off
        }
    Return
}
If I messed up something, please tell me.

Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 08:09
by Helgef
You could turn on the hotkeys once, and make them context sensitive.
There is also the BlockInput command.
I do a manual #l and have a password on my pc.

Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 08:48
by SpeedMaster
wolf_II wrote:At the moment I don't understand why you would need to have mouse buttons treated differently.
Young children can be confused about whether to use the right or left button on a mouse. :problem:
There are many sites that offer interesting things for young children. The problem is that most browsers displays a menu when you click the right button, which can cause problems. :think:

More explanations here...
http://www.hackingpages.com/2016/07/dis ... sktop.html

Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 09:24
by wolf_II
Helgef wrote:You could turn on the hotkeys once, and make them context sensitive.
Thanks for the suggestion! :thumbup:

Code: Select all

    ;-----------------------------------------
    ; define AllKeys as a pipe delimited list
    ;-----------------------------------------
    AllKeys := "NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins"
    Loop, 254
        If KeyName := GetKeyName(Format("VK{:X}", A_Index))
            AllKeys .= "|" KeyName
    For Key, Replacement in {Control: "Ctrl", Escape: "Esc"}
        AllKeys := StrReplace(AllKeys, Key, Replacement)

    ;----------------------------------------------------------
    ; turn on the hotkeys once and make them context sensitive
    ;----------------------------------------------------------
    Hotkey, If, Block = "On"
    For each, KeyName in StrSplit(AllKeys, "|")
        Hotkey, *%KeyName%, Block_Input, %Block% UseErrorLevel

Return ; end of auto-execute section


!F1:: Block := "On"  ; disable keys
!F2:: Block := "Off" ; enable keys


;-------------------------------------------------------------------------------
Block_Input: ; context sensitive
;-------------------------------------------------------------------------------
    Progress, B1 ZH0, Keyboard and mouse are locked!`nPress Alt+F2 to unlock.
    Sleep, 2000
    Progress, Off

Return


#If, Block = "On"
#If ; end of context

Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 10:23
by SpeedMaster
Helgef wrote:There is also the BlockInput command.
I was wondering why Feiyue did not use this command. :think:

Good luck to regain control of the keyboard in less than a minute without using control-alt-delete or a timed event. :angel:

Code: Select all

a::
BlockInput On

sleep, 60000  ;timed event to regain control of the keyboard
exitapp
return

b::
BlockInput off   ; This just does not work !!!
return
wolf_II wrote:Here is a version, that facilitates readability...
Of course it facilitates readability but it loses its portability. :|
If someone can improve the function of iphilip and mix it with my attempt it would be great :D

Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 11:43
by iPhilip
Hi SpeedMaster,

I modified the function above by adding a timeout parameter (in seconds) and changed the default parameters for the other parameters.

I hope that works for you.

Re: Disable all keyboard buttons

Posted: 06 Jul 2017, 18:19
by SpeedMaster
iPhilip wrote:Hi SpeedMaster,

I modified the function above by adding a timeout parameter (in seconds) and changed the default parameters for the other parameters.

I hope that works for you.
Thank you for your help iPhilip. The timeout parameter is good idea. :D
I tested the code and I noticed taht the message appeared only once and also noticed that it was not possible to disable only the right mouse button.
So I tweaked the function and added an option (displayonce=) to display the message only once or more and also the possiblity to disable the right mouse button only (mouse=2). :dance:
everything works fine now the only thing is that the code need to be cleaned up :?

Here is the function

Code: Select all

hk(keyboard:=0, mouse:=0, message:="", timeout:=3, displayonce:=0) { 
   static AllKeys, z, d
   z:=message
   d:=displayonce
      For k,v in AllKeys {
           Hotkey, *%v%, Block_Input, off         ; initialisation
      }
   if !AllKeys {
      s := "||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
      Loop, 254
         k := GetKeyName(Format("VK{:0X}", A_Index))
       , s .= InStr(s, "|" k "|") ? "" : k "|"
      For k,v in {Control:"Ctrl",Escape:"Esc"}
         AllKeys := StrReplace(s, k, v)
      AllKeys := StrSplit(Trim(AllKeys, "|"), "|")
   }
   ;------------------
   if (mouse!=2)  ; if mouse=1 disable right and left mouse buttons  if mouse=0 don't disable mouse buttons
    {
        For k,v in AllKeys {
           IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
           Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
        }
    }
   if (mouse=2)   ;disable right mouse button (but not left mouse)
    {                
     ExcludeKeys:="LButton"
      For k,v in AllKeys {
           IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
           if v not in %ExcludeKeys%
           Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
        }
    }
   if d
    {
   if (z != "") {
      Progress, B1 ZH0, %z%
      SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
     }
   Block_Input:
   if (d!=1)
    {
   if (z != "") {
      Progress, B1 ZH0, %z%
      SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
     }
   Return
   TimeoutTimer:
   Progress, Off
   Return
}

!F1::hk(1,1,"Keyboard keys and mouse buttons disabled!`nPress Alt+F2 to enable")   ; Disable all keyboard keys and mouse buttons
!F2::hk(0,0,"Keyboard keys and mouse buttons restored!")         ; Enable all keyboard keys and mouse buttons
!F3::hk(1,0,"Keyboard keys disabled!`nPress Alt+F2 to enable")   ; Disable all keyboard keys (but not mouse buttons)
!F4::hk(0,1,"Mouse buttons disabled!`nPress Alt+F2 to enable")   ; Disable all mouse buttons (but not keyboard keys)
!F5::hk(1,2,"Keyboard keys and Right Mouse button disabled!`nPress Alt+F2 to enable")   ; Disable all keyboard keys and right mouse button only
!F6::hk(0,2,"Right Mouse button disabled!`nPress Alt+F2 to enable",3,1)   ; Disable right mouse button only and show message only once

Re: Disable all keyboard buttons

Posted: 06 Jul 2019, 08:26
by SorrymyEN
Hi, SpeedMaster

Your code has been very useful to me and I am trying to make the screen message more emphatic as an OSD text because it was barely visible in certain contexts. Everything worked fine except that the blocked keyboard prompt only appears once, not every click. Could you check what I'm doing wrong? My thanks...

Code: Select all

OSD1(text)
{
	#Persistent
	Progress, hide %Height% W2000 H43 b zh0 cwFF0000 FM20 CTFFFFFF,, %text%, AutoHotKeyProgressBar, Backlash BRK
	WinSet, TransColor, 000000 255, AutoHotKeyProgressBar
	Progress, show
	SetTimer, RemoveToolTip, 5000
	Return
	SetTimer, RemoveToolTip, Off
	Progress, Off
	return
}

OSD2(text)
{
	#Persistent
	Progress, hide %Height% W2000 H43 b zh0 cw009F00 FM20 CTFFFFFF,, %text%, AutoHotKeyProgressBar, Backlash BRK
	WinSet, TransColor, 000000 255, AutoHotKeyProgressBar
	Progress, show
	SetTimer, RemoveToolTip, 4000
	Return
RemoveToolTip:
	SetTimer, RemoveToolTip, Off
	Progress, Off
	return
}

hk(keyboard:=0, mouse:=0, message:="", timeout:=3, displayonce:=0) { 
   static AllKeys, z, d
   z:=message
   d:=displayonce
      For k,v in AllKeys {
           Hotkey, *%v%, Block_Input, off         ; initialisation
      }
   if !AllKeys {
      s := "||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
      Loop, 254
         k := GetKeyName(Format("VK{:0X}", A_Index))
       , s .= InStr(s, "|" k "|") ? "" : k "|"
      For k,v in {Control:"Ctrl",Escape:"Esc"}
         AllKeys := StrReplace(s, k, v)
      AllKeys := StrSplit(Trim(AllKeys, "|"), "|")
   }
   ;------------------
   if (mouse!=2)  ; if mouse=1 disable right and left mouse buttons  if mouse=0 don't disable mouse buttons
    {
        For k,v in AllKeys {
           IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
           Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
        }
    }
   if (mouse=2)   ;disable right mouse button (but not left mouse)
    {                
     ExcludeKeys:="LButton"
      For k,v in AllKeys {
           IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
           if v not in %ExcludeKeys%
           Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
        }
    }
   if d
    {
   if (z != "") {
      Progress, B1 ZH0, %z%
      SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
     }
   Block_Input:
   if (d!=1)
    {
   if (z != "") {
      Progress, B1 ZH0, %z%
      SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
     }
   Return
   TimeoutTimer:
   Progress, Off
   Return
}

!F1::hk(1,1),OSD1("KEYBOARD AND MOUSE LOCKED!  -  ALT+F2 TO UNLOCK")     ;Disable all keyboard keys and mouse buttons
!F2::hk(0.0),OSD2("KEYBOARD AND MOUSE UNLOCKED!  -  ALT-F1 TO LOCK")     ;Enable all keyboard keys and mouse buttons

Re: Disable all keyboard buttons

Posted: 06 Jul 2019, 17:37
by SpeedMaster
SorrymyEN wrote:
06 Jul 2019, 08:26
Could you check what I'm doing wrong? My thanks..
OSD() was not part of the function hk() :think:

try this:

Code: Select all

#SingleInstance force

hk(keyboard:=0, mouse:=0, message:="", timeout:=3, displayonce:=0) { 
   static AllKeys, z, d, kb, ms
   z:=message, d:=displayonce, kb:=keyboard, ms:=mouse
      For k,v in AllKeys {
           Hotkey, *%v%, Block_Input, off         ; initialisation
      }
   if !AllKeys {
      s := "||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
      Loop, 254
         k := GetKeyName(Format("VK{:0X}", A_Index))
       , s .= InStr(s, "|" k "|") ? "" : k "|"
      For k,v in {Control:"Ctrl",Escape:"Esc"}
         AllKeys := StrReplace(s, k, v)
      AllKeys := StrSplit(Trim(AllKeys, "|"), "|")
   }
   ;------------------
   if (mouse!=2)  ; if mouse=1 disable right and left mouse buttons  if mouse=0 don't disable mouse buttons
    {
        For k,v in AllKeys {
           IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
           Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
        }
    }
   if (mouse=2)   ;disable right mouse button (but not left mouse)
    {                
     ExcludeKeys:="LButton"
      For k,v in AllKeys {
           IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
           if v not in %ExcludeKeys%
           Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
        }
    }
   if d
    {
   if (z != "") {
      Progress, %Height% W2000 H43 b zh0 cwFF0000 FM20 CTFFFFFF,, %z%
      SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
     }
   Block_Input:
   if (d!=1)
    {
   if (z != "") {
	    if (kb || ms)
			Progress, W2000 H43 b zh0 cwFF0000 FM20 CTFFFFFF,, %z%
		else
			Progress, W2000 H43 b zh0 cw009F00 FM20 CTFFFFFF,, %z%
		SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
     }
   Return
   TimeoutTimer:
   Progress, Off
   Return
}

!F1::hk(1,1,"KEYBOARD AND MOUSE LOCKED!  -  ALT+F2 TO UNLOCK")   ; Disable all keyboard keys and mouse buttons
!F2::hk(0,0,"KEYBOARD AND MOUSE UNLOCKED!  -  ALT-F1 TO LOCK")   ; Enable all keyboard keys and mouse buttons

Regards

Re: Disable all keyboard buttons

Posted: 07 Jul 2019, 05:47
by SpeedMaster
Hello,
I added an option to also hide the screen and choose the hiding color 8-) :thumbup:
Press Alt + F3 to test

how to use the function:
hk(keyboard:=false, mouse:=0, message:="", timeout:=3, displayonce:=false,screen:=false, screencolor:="blue")

keyboard (true/false).......................... disable/enable keyboard
mouse=1........................................ disable all mouse buttons
mouse=2........................................ disable right mouse button only
msessage....................................... display a message
timeout........................................ how long to display the message in sec
displayonce (true/false) ...................... display a message only once or always
hide the screen (true/false)................... hide or show everything
ScreenColor ................................... RGB Hex background color for the hiding GUI

Code: Select all

#SingleInstance force

!F1::hk(1,1,"KEYBOARD AND MOUSE LOCKED!  -  ALT+F2 TO UNLOCK")              ; Disable all keyboard keys and mouse buttons
!F2::hk(0,0,"KEYBOARD AND MOUSE UNLOCKED!  -  ALT-F1 TO LOCK")              ; Enable all keyboard keys and mouse buttons
!F3::hk(1,1,"KEYBOARD MOUSE AND SCREEN LOCKED!  -  ALT+F2 TO UNLOCK",,,1,"teal")   ; Disable keyboard mouse and screen


hk(keyboard:=false, mouse:=0, message:="", timeout:=3, displayonce:=false,screen:=false, screencolor:="blue") { 

;keyboard (true/false).......................... disable/enable keyboard
;mouse=1........................................ disable all mouse buttons
;mouse=2........................................ disable right mouse button only
;msessage....................................... display a message
;timeout........................................ how long to display the message in sec
;displayonce (true/false) ...................... display a message only once or always
;hide the screen (true/false)................... hide or show everything
;ScreenColor ................................... RGB Hex background color for the hiding GUI 


   static AllKeys, z, d, kb, ms, sc
   z:=message, d:=displayonce, kb:=keyboard, ms:=mouse, sc:=screen

      For k,v in AllKeys {
           Hotkey, *%v%, Block_Input, off         ; initialisation
      }
   if !AllKeys {
      s := "||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
      Loop, 254
         k := GetKeyName(Format("VK{:0X}", A_Index))
       , s .= InStr(s, "|" k "|") ? "" : k "|"
      For k,v in {Control:"Ctrl",Escape:"Esc"}
         AllKeys := StrReplace(s, k, v)
      AllKeys := StrSplit(Trim(AllKeys, "|"), "|")
   }
   ;------------------
   if (mouse!=2)  ; if mouse=1 disable right and left mouse buttons  if mouse=0 don't disable mouse buttons
    {
        For k,v in AllKeys {
           IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
           Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
        }
    }
   if (mouse=2)   ;disable right mouse button (but not left mouse)
    {                
     ExcludeKeys:="LButton"
      For k,v in AllKeys {
           IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
           if v not in %ExcludeKeys%
           Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
        }
    }
   if d
    {
   if (z != "") {
      Progress, +AlwaysOnTop W2000 H43 b zh0 cwFF0000 FM20 CTFFFFFF,, %z%
      SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
     }
   Block_Input:
   if (d!=1)
    {
   if (z != "") {
	    if (kb || ms)
			Progress, W2000 H43 b zh0 cwFF0000 FM20 CTFFFFFF,, %z%
		else
			Progress, W2000 H43 b zh0 cw009F00 FM20 CTFFFFFF,, %z%
		SetTimer, TimeoutTimer, % -timeout*1000
   }
   else
      Progress, Off
     }


if (sc=1)
   { 
     Gui screen:  -Caption
     Gui screen: Color,  % screencolor
     Gui screen: Show, x0 y0 h74 w%a_screenwidth% h%a_screenheight%, New GUI Window
   }
   else
      gui screen: Hide


   Return
   TimeoutTimer:
   Progress, Off
   Return
}
Cheers

Re: Disable all keyboard buttons

Posted: 07 Jul 2019, 08:09
by SorrymyEN
Oh yes, more emphatic that this is impossible :clap:

ps.: just do not forget to assign screen lock to !F7 so as not to conflict with previously used keys.

Re: Disable all keyboard buttons

Posted: 26 Nov 2019, 15:01
by zvit
When I release the keys with ALT-F2, there is one problem.
It is not releasing my backquote key (`) which I have mapped to del.
The key just does nothing.

Re: Disable all keyboard buttons

Posted: 12 Oct 2020, 12:20
by rbreaves
@feiyue @SpeedMaster Would you guys be ok with me adding this code to my GPLv2 (also open to those that would prefer MIT) open source project https://github.com/rbreaves/kinto? I really like the ability to disable the keyboard entirely, very useful for quick keyboard cleanings without needing to lock my computer or disrupt my workflow.

Re: Disable all keyboard buttons

Posted: 13 Oct 2020, 11:09
by feiyue
I don't mind. :D

Re: Disable all keyboard buttons

Posted: 12 Jul 2022, 08:00
by A Keymaker
How these scripts would have to be modified in order to:

A] block also the Esc key

B] block also all keys on a wireless portable keyboard connected via USB dongle

C] block all mouse clicks

D] unblock all input after two different consecutive mouse movements that happens within a 1 second span, in form of: from left to right or right to left - and / or - from up to down or from down to up

E] close the scripts [i.e. the AHK file] when input is restored

?


Explanation / reasoning:

Ad A] My cat does not differentiate between keys, so all keys on keyboard have to be dead when I leave the room and execute this fail-safe script

Ad B] Special keys [e.g. Shift] and multimedia keys [e.g. Play / Pause] seem to be blocked on this particular keyboard - but ordinary ones [e.g. q] are not

Ad C] Mouse could fall from a desk and accidentally click itself, thus change something

Ad D] I chose a jumpy opposite movements of mouse as the signal to unblock all other input signals. A mouse movement will also turn back my monitor, as this AHK script I want to run simultaneously with my BAT script that turns off my screens [viewtopic.php?f=76&t=106180&p=471736#p471736]

Ad E] If the script is not closed, then in my Tray the number of AHK icons will grow with time, showing another instance of script whenever during a session I will leave the room. There really is no point in showing it in Tray once its job is over