Disable all keyboard buttons

Post your working scripts, libraries and tools
User avatar
RunarSF
Posts: 27
Joined: 01 Jul 2017, 11:48
GitHub: RunarSF
Location: Norway
Contact:

Disable all keyboard buttons

01 Jul 2017, 14:04

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
Attachments
disable keys.ahk
(1.66 KiB) Downloaded 533 times
There are two kinds of people in the world: those who can extrapolate from incomplete data.
feiyue
Posts: 162
Joined: 08 Aug 2014, 04:08

Re: Disable all keyboard buttons

04 Jul 2017, 16:51

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
User avatar
SpeedMaster
Posts: 324
Joined: 12 Nov 2016, 16:09

Re: Disable all keyboard buttons

05 Jul 2017, 06:14

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


iPhilip
Posts: 408
Joined: 02 Oct 2013, 12:21

Re: Disable all keyboard buttons

06 Jul 2017, 03:01

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.
Last edited by iPhilip on 06 Jul 2017, 11:37, edited 1 time in total.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
User avatar
SpeedMaster
Posts: 324
Joined: 12 Nov 2016, 16:09

Re: Disable all keyboard buttons

06 Jul 2017, 05:46

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



wolf_II
Posts: 2685
Joined: 08 Feb 2015, 20:55

Re: Disable all keyboard buttons

06 Jul 2017, 07:32

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.
Helgef
Posts: 3898
Joined: 17 Jul 2016, 01:02
Contact:

Re: Disable all keyboard buttons

06 Jul 2017, 08:09

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.
User avatar
SpeedMaster
Posts: 324
Joined: 12 Nov 2016, 16:09

Re: Disable all keyboard buttons

06 Jul 2017, 08:48

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
wolf_II
Posts: 2685
Joined: 08 Feb 2015, 20:55

Re: Disable all keyboard buttons

06 Jul 2017, 09:24

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
User avatar
SpeedMaster
Posts: 324
Joined: 12 Nov 2016, 16:09

Re: Disable all keyboard buttons

06 Jul 2017, 10:23

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
iPhilip
Posts: 408
Joined: 02 Oct 2013, 12:21

Re: Disable all keyboard buttons

06 Jul 2017, 11:43

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.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
User avatar
SpeedMaster
Posts: 324
Joined: 12 Nov 2016, 16:09

Re: Disable all keyboard buttons

06 Jul 2017, 18:19

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
SorrymyEN
Posts: 23
Joined: 30 Apr 2017, 23:22

Re: Disable all keyboard buttons

06 Jul 2019, 08:26

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
User avatar
SpeedMaster
Posts: 324
Joined: 12 Nov 2016, 16:09

Re: Disable all keyboard buttons

06 Jul 2019, 17:37

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
User avatar
SpeedMaster
Posts: 324
Joined: 12 Nov 2016, 16:09

Re: Disable all keyboard buttons

07 Jul 2019, 05:47

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
SorrymyEN
Posts: 23
Joined: 30 Apr 2017, 23:22

Re: Disable all keyboard buttons

07 Jul 2019, 08:09

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.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: BruceO, SpeedMaster and 30 guests