Advertisement
EzFlow997

Lock Script with AHK

Mar 11th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. hk(keyboard:=0, mouse:=0, message:="", timeout:=3, displayonce:=0) {
  2. static AllKeys, z, d
  3. AllKeys := ""
  4. z:=message
  5. d:=displayonce
  6. For k,v in AllKeys {
  7. Hotkey, *%v%, Block_Input, off ; initialisation
  8. }
  9. if !AllKeys {
  10. s := "||NumpadEnter|Home|End|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
  11. Loop, 254
  12. k := GetKeyName(Format("VK{:0X}", A_Index))
  13. , s .= InStr(s, "|" k "|") ? "" : k "|"
  14. For k,v in {Control:"Ctrl",Escape:"Esc"}
  15. AllKeys := StrReplace(s, k, v)
  16. AllKeys := StrSplit(Trim(AllKeys, "|"), "|")
  17. }
  18. ;------------------
  19. if (mouse!=2) ; if mouse=1 disable right and left mouse buttons if mouse=0 don't disable mouse buttons
  20. {
  21. For k,v in AllKeys {
  22. IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
  23. Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
  24. }
  25. }
  26. if (mouse=2) ;disable right mouse button (but not left mouse)
  27. {
  28. ExcludeKeys:="LButton"
  29. For k,v in AllKeys {
  30. IsMouseButton := Instr(v, "Wheel") || Instr(v, "Button")
  31. if v not in %ExcludeKeys%
  32. Hotkey, *%v%, Block_Input, % (keyboard && !IsMouseButton) || (mouse && IsMouseButton) ? "On" : "Off"
  33. }
  34. }
  35. if d
  36. {
  37. if (z != "") {
  38. Progress, B1 ZH0, %z%
  39. SetTimer, TimeoutTimer, % -timeout*1000
  40. }
  41. else
  42. Progress, Off
  43. }
  44. Block_Input:
  45. if (d!=1)
  46. {
  47. if (z != "") {
  48. Progress, B1 ZH0, %z%
  49. SetTimer, TimeoutTimer, % -timeout*1000
  50. }
  51. else
  52. Progress, Off
  53. }
  54. Return
  55. TimeoutTimer:
  56. Progress, Off
  57. Return
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement