Disable all keyboard buttons
Disable all keyboard buttons
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)
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)
- Attachments
-
- disable keys.ahk
- (1.66 KiB) Downloaded 2718 times
There are two kinds of people in the world: those who can extrapolate from incomplete data.
Re: Disable all keyboard buttons
Good idea!
Your ideas can be succinctly implemented:
Your ideas can be succinctly implemented:
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
- SpeedMaster
- Posts: 494
- Joined: 12 Nov 2016, 16:09
Re: Disable all keyboard buttons
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 ?
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 ?
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
Here is a version that allows keyboard keys and/or mouse buttons to be disabled:Cheers!
Edit: Added a timeout parameter to the function and changed the default values of the other parameters.
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)
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 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
- SpeedMaster
- Posts: 494
- Joined: 12 Nov 2016, 16:09
Re: Disable all keyboard buttons
Thanks a lot iPhilip you did a fantastic job .
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.
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.
here is my attempt
(hide the message after 2 sec and possiblity to lock only the ritght mouse button)
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.
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.
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
Here is a version, that facilitates readability, because I need this bigly . Thanks to feiyue for your code , 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.If I messed up something, please tell me.
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
}
Re: Disable all keyboard buttons
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.
There is also the BlockInput command.
I do a manual #l and have a password on my pc.
- SpeedMaster
- Posts: 494
- Joined: 12 Nov 2016, 16:09
Re: Disable all keyboard buttons
Young children can be confused about whether to use the right or left button on a mouse.wolf_II wrote:At the moment I don't understand why you would need to have mouse buttons treated differently.
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.
More explanations here...
http://www.hackingpages.com/2016/07/dis ... sktop.html
Re: Disable all keyboard buttons
Thanks for the suggestion!Helgef wrote:You could turn on the hotkeys once, and make them context sensitive.
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
- SpeedMaster
- Posts: 494
- Joined: 12 Nov 2016, 16:09
Re: Disable all keyboard buttons
I was wondering why Feiyue did not use this command.Helgef wrote:There is also the BlockInput command.
Good luck to regain control of the keyboard in less than a minute without using control-alt-delete or a timed event.
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
Of course it facilitates readability but it loses its portability.wolf_II wrote:Here is a version, that facilitates readability...
If someone can improve the function of iphilip and mix it with my attempt it would be great
Re: Disable all keyboard buttons
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.
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 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
- SpeedMaster
- Posts: 494
- Joined: 12 Nov 2016, 16:09
Re: Disable all keyboard buttons
Thank you for your help iPhilip. The timeout parameter is good idea.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.
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).
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
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...
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
- SpeedMaster
- Posts: 494
- Joined: 12 Nov 2016, 16:09
Re: Disable all keyboard buttons
OSD() was not part of the function hk()
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
- SpeedMaster
- Posts: 494
- Joined: 12 Nov 2016, 16:09
Re: Disable all keyboard buttons
Hello,
I added an option to also hide the screen and choose the hiding color
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
Cheers
I added an option to also hide the screen and choose the hiding color
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
}
Re: Disable all keyboard buttons
Oh yes, more emphatic that this is impossible
ps.: just do not forget to assign screen lock to !F7 so as not to conflict with previously used keys.
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
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.
It is not releasing my backquote key (`) which I have mapped to del.
The key just does nothing.
Re: Disable all keyboard buttons
@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
I don't mind.
- A Keymaker
- Posts: 457
- Joined: 31 May 2022, 13:46
- Location: Donjon du Château de Mérovingien
Re: Disable all keyboard buttons
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
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
Last edited by A Keymaker on 04 Jul 2023, 11:40, edited 1 time in total.