Advertisement
TheNoobPolice

Winkey disabler / shortcut binder

Feb 28th, 2023 (edited)
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. kb := new AllKeyBinder(Func("KeyEvent"), "*")
  2. return
  3.  
  4. KeyEvent(code, name, state) {
  5.     static PreventSwitch := "", Toggle := ""
  6.    
  7.     if (name != "LWin") {                          
  8.         if (GetKeyState("LWin", "P") && state) {   
  9.             PreventSwitch := 1                     
  10.             if (name = "Numpad2")                  
  11.                 Run, Explorer.exe      
  12.             else                                   
  13.                 Sendinput {LWin Down}              
  14.             }                                      
  15.         Sendinput, % "{Blind}{"name (state ? " Down}" : " Up}")
  16.     }
  17.     else {                                     
  18.         if state                                   
  19.             PreventSwitch := 0  
  20.         else
  21.             Sendinput, % PreventSwitch ? (GetKeyState("LWin") ? "{LWin Up}" : "") : ("#^{"((Toggle:=!Toggle) ? "Left}" : "Right}"))
  22.     }
  23. }
  24.  
  25. class AllKeyBinder{     ; By evilC
  26.     __New(callback, pfx := "~*"){
  27.         keys := {}
  28.         this.Callback := callback
  29.         Loop 512 {
  30.             i := A_Index
  31.             code := Format("{:x}", i)
  32.             n := GetKeyName("sc" code)
  33.             if (!n || keys.HasKey(n))
  34.                 continue
  35.            
  36.             keys[n] := code
  37.            
  38.             fn := this.KeyEvent.Bind(this, i, n, 1)
  39.             hotkey, % pfx "SC" code, % fn, On
  40.            
  41.             fn := this.KeyEvent.Bind(this, i, n, 0)
  42.             hotkey, % pfx "SC" code " up", % fn, On        
  43.         }
  44.     }
  45.    
  46.     KeyEvent(code, name, state){
  47.         this.Callback.Call(code, name, state)
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement