Jump to content

Limit Keyboard Input


ken82m
 Share

Recommended Posts

This function allows you to block only certain keys on the keyboard.

I originally created it so I could disable the windows keys.

Kenny

#cs ----------------------------------------------------------------------------
 Function:   _LimitInputEx
 Author:       Kenneth P. Morrissey 
 Based on:   _BlockInputEx() by Rasim and MrCreatoR

 Script Function:
    This function limits keyboard input to keys specified.

--------------------------------------------------------------------------------

_LimitInputEx ( $sBlock = 0 , [ sExclude = ""  , [ $sALTExclude = "" ]] )

Parameters
$sBlock:            0 = Unblock(Default)
                    1 = Block

sExclude:       List of key(s) to be blocked
                        List of keys should be in quotes
                        For multiple keys separate them with |
                        For example: "0x1B|0x70|0x71|0x72|0x73"

sALTExclude:        List of key(s) combined with ALT to be blocked
                        List of keys should be in quotes
                        For multiple keys separate them with |
                        For example: "0x09|0x73" would block ALT-TAB and ALT-F4

Return Value:       Success: Returns 1
                    Failure: Returns 0
                        Sets @error to 1

Remarks:            Ctrl+Alt+Del cannot be blocked due to a Windows API feature.

Operating System "_LimitInputEx" Results 
Windows 95: Not tested, probably won't work.
Windows 98/Me: Not tested, probably won't work.
Windows NT 4:  User input is blocked and AutoIt can simulate most input. 
Windows 2000:  User input is blocked and AutoIt can simulate most input. 
Windows XP: User input is blocked and AutoIt can simulate most input.
Windows Vista: User input is blocked and AutoIt can simulate most input.
___________________________________

Key List:
0x08   BACKSPACE key
0x09   TAB key
0x0D   ENTER key
0x10   SHIFT key
0x11   CTRL key
0x12   ALT key
0x14   CAPS LOCK key
0x1B   ESC key
0x20   SPACEBAR
0x21   PAGE UP key
0x22   PAGE DOWN key
0x23   END key
0x24   HOME key
0x25   LEFT ARROW key
0x26   UP ARROW key
0x27   RIGHT ARROW key
0x28   DOWN ARROW key
0x2A   PRINT key
0x2C   PRINT SCREEN key
0x2D   INS key
0x2E   DEL key
0x30   0 key
0x31   1 key
0x32   2 key
0x33   3 key
0x34   4 key
0x35   5 key
0x36   6 key
0x37   7 key
0x38   8 key
0x39   9 key
0x41   A key
0x42   B key
0x43   C key
0x44   D key
0x45   E key
0x46   F key
0x47   G key
0x48   H key
0x49   I key
0x4A   J key
0x4B   K key
0x4C   L key
0x4D   M key
0x4E   N key
0x4F   O key
0x50   P key
0x51   Q key
0x52   R key
0x53   S key
0x54   T key
0x55   U key
0x56   V key
0x57   W key
0x58   X key
0x59   Y key
0x5A   Z key
0x5B   Left Windows key
0x5C   Right Windows key
0x60   Numeric keypad 0 key
0x61   Numeric keypad 1 key
0x62   Numeric keypad 2 key
0x63   Numeric keypad 3 key
0x64   Numeric keypad 4 key
0x65   Numeric keypad 5 key
0x66   Numeric keypad 6 key
0x67   Numeric keypad 7 key
0x68   Numeric keypad 8 key
0x69   Numeric keypad 9 key
0x6A   Numpad Multiply key
0x6B   Numpad Add key
0x6C   Numpad Separator key
0x6D   Numpad Subtract key
0x6E   Numpad Decimal key
0x6F   Numpad Divide key
0x70   F1 key
0x71   F2 key
0x72   F3 key
0x73   F4 key
0x74   F5 key
0x75   F6 key
0x76   F7 key
0x77   F8 key
0x78   F9 key
0x79   F10 key
0x7A   F11 key
0x7B   F12 key
0x7C   F13 key
0x7D   F14 key
0x7E   F15 key
0x7F   F16 key
0x80   F17 key
0x81   F18 key
0x82   F19 key
0x83   F20 key
0x84   F21 key
0x85   F22 key
0x86   F23 key
0x87   F24 key
0x90   NUM LOCK key
0x91   SCROLL LOCK key
0xA0   Left SHIFT key
0xA1   Right SHIFT key
0xA2   Left CONTROL key
0xA3   Right CONTROL key
0xBA  ;
0xBB   =
0xBC   ","
0xBD   -
0xBE   .
0xBF   /
0xC0   `
0xDB   [
0xDC   \
0xDD   ]
___________________________________

Example of using this UDF:
   #Include <LimitInputEx.au3>

   _LimitInputEx(1, "0x1B|0x70|0x71|0x72|0x73");0x1B={ESC},0x70="{F1}",0x71="{F2}",0x72="{F3}",0x73="{F4}"

    AdlibEnable("_Quit", 10000);This is only for testing, so if anything go wrong, the script will exit after 10 seconds.

   While 1
       Sleep(100)
   WEnd

   Func OnAutoITExit()
       _LimitInputEx()
   EndFunc
#ce ----------------------------------------------------------------------------
#include <WinAPI.au3>

Global $ah_Hooks
Global $ah_Hooks2

Func _LimitInputEx($sBlock=0, $sExclude="", $sALTExclude="")
    Select
        Case IsArray($ah_Hooks) AND $sBlock = 0
            If $ah_Hooks[1] > 0 Then DllCallbackFree($ah_Hooks[1])
            If $ah_Hooks[2] > 0 Then DllCallbackFree($ah_Hooks[2])
            
            If $ah_Hooks[3] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_Hooks[3])
            If $ah_Hooks[4] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_Hooks[4])
            Return 1
            
        Case IsArray($ah_Hooks) AND $sBlock = 1
            If $ah_Hooks[1] > 0 Then DllCallbackFree($ah_Hooks[1])
            If $ah_Hooks[2] > 0 Then DllCallbackFree($ah_Hooks[2])
            
            If $ah_Hooks[3] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_Hooks[3])
            If $ah_Hooks[4] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_Hooks[4])
            
        Case IsNumber($sBlock) And $sBlock > 0
            Local $pStub_KeyProc = 0, $hHookKeyboard = 0
            
                $pStub_KeyProc = DllCallbackRegister("_Key_Proc", "int", "int;ptr;ptr")
                $hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _
                    _WinAPI_GetModuleHandle(0), 0)
            
            Local  $aRet[5] = ["|" & $sExclude & "|", $pStub_KeyProc, $hHookKeyboard]
            Global $ah_Hooks2 = "|" & $sALTExclude & "|"
            
            Global $ah_Hooks
            $ah_Hooks = $aRet
            Return 1
        Case Else
            Return SetError(1, 0, 0)
    EndSelect
EndFunc

Func _Key_Proc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($ah_Hooks[3], $nCode, $wParam, $lParam)
    
    Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)
    Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")
    Local $flags = DllStructGetData($KBDLLHOOKSTRUCT, "flags")
;Local $scanCode = DllStructGetData($KBDLLHOOKSTRUCT, "scanCode")
    
;Disable ALT-TAB
    If $flags = $LLKHF_ALTDOWN AND StringInStr($ah_Hooks2, "|0x" & Hex($vkCode, 2) & "|") Then Return 1
    If StringInStr($ah_Hooks[0], "|0x" & Hex($vkCode, 2) & "|") Then Return 1
    _WinAPI_CallNextHookEx($ah_Hooks[3], $nCode, $wParam, $lParam)
EndFunc
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Added parameter to block ALT+KEY combinations.

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Added parameter to block ALT+KEY combinations.

Hello,

This is intresting, i was looking for something like that ... my script block all keys except one i select (ESC). But it does'nt work as i want so i will try this. Thank you.

Link to comment
Share on other sites

Add some code to ken82 work:

#include <file.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

#include <array.au3>
#Include <LimitInputEx.au3>
#include <Misc.au3>
#NoTrayIcon

dim $my_BACKSPACE, $my_TAB, $my_ENTER, $SHIFT, $my_CTRL, $my_ALT, $my_CAPSLOCK, $my_ESC, $my_SPACEBAR, $my_PAGEUP, $my_PAGEDOWN, $my_END, $my_HOME, $my_LEFTARROW, $my_UPARROW, $my_RIGHTARROW, $my_DOWNARROW, $my_PRINT, $my_PRINTSCREEN, $my_INS, $my_DEL, $my_0, $my_1, $my_2, $my_3, $my_4, $my_5, $my_6, $my_7, $my_8, $my_9
dim $my_A, $my_B, $my_C, $my_D, $my_E, $my_F, $my_G, $my_H, $my_I, $my_J, $my_K, $my_L, $my_M, $my_N, $my_O, $my_P, $my_Q, $my_R, $my_S, $my_T, $my_U, $my_V, $my_W, $my_X, $my_Y, $my_Z, $my_LeftWindows, $my_RightWindows
dim $my_Numpad0, $my_Numpad1, $my_Numpad2, $my_Numpad3, $my_Numpad4, $my_Numpad5, $my_Numpad6, $my_Numpad7, $my_Numpad8, $my_Numpad9, $my_NumpadMultiply, $my_NumpadAdd, $my_NumpadSeparator, $my_NumpadSubtract, $my_NumpadDecimal, $my_NumpadDivide
dim $my_F1, $my_F2, $my_F3, $my_F4, $my_F5, $my_F6, $my_F7, $my_F8, $my_F9, $my_F10, $my_F11, $my_F12, $my_F13, $my_F14, $my_F15, $my_F16, $my_F17, $my_F18, $my_F19, $my_F20, $my_F21, $my_F22, $my_F23, $my_F24, $my_F17, $my_F18, $my_F19, $my_F20, $my_F21, $my_F22, $my_F23, $my_F24
dim $my_NUMLOCK, $my_SCROLLLOCK, $my_LeftSHIFT, $my_RightSHIFT, $my_LeftCONTROL, $my_RightCONTROL

dim $var[2], $disabled_keys = ""
dim $f_go = 0, $click = 0

;////////////////////////////////////////////////////////////////////
;//           verify and read .Ini
;////////////////////////////////////////////////////////////////////
If $CmdLine[0] = 0 Then

    If Not FileExists(@ScriptDir & "\Keybonff.ini") Then 
        _buildini()
        Sleep(250)
    EndIf
    
    $CountLines = _FileCountLines(@ScriptDir & "\Keybonff.ini")
    if $CountLines <> 106 Then
        MsgBox(64, ".ini malformed", ".ini is not in standard format, must have all 106 rows."& @CRLF & "Yours has " & $CountLines & " !")
        Exit
    EndIf
    
    $var = IniReadSection(@ScriptDir & "\Keybonff.ini", "Mykeyboard")
    _assign()

ElseIf $CmdLine[0] = 1 Then

    If Not FileExists($CmdLine[1]) Then 
        msgbox(0,"Alert!",".ini you specified NOT exist !")
        Exit
    EndIf

    $CountLines = _FileCountLines($CmdLine[1])
    if $CountLines <> 106 Then
        MsgBox(64, ".ini malformed", ".ini is not in standard format, must have all 106 rows."& @CRLF & "Yours has " & $CountLines & " !")
        Exit
    EndIf


    $var = IniReadSection($CmdLine[1], "Mykeyboard")
    _assign()

EndIf
    
;////////////////////////////////////////////////////////////////////
;//                   MAIN
;////////////////////////////////////////////////////////////////////
if $f_go = 1 then 
;---------------------------------------------------------------------------------- build string of disable key
    if $my_BACKSPACE <> "on" then $disabled_keys = $disabled_keys & "|" & "0x08" & "|"
    if $my_TAB <> "on" then $disabled_keys = $disabled_keys & "|" & "0x09" & "|"
    if $my_ENTER <> "on" then $disabled_keys = $disabled_keys & "|" & "0x0D" & "|"
    if $SHIFT <> "on" then $disabled_keys = $disabled_keys & "|" & "0x10" & "|"
    if $my_CTRL <> "on" then $disabled_keys = $disabled_keys & "|" & "0x11" & "|"
    if $my_ALT <> "on" then $disabled_keys = $disabled_keys & "|" & "0x12" & "|"
    if $my_CAPSLOCK <> "on" then $disabled_keys = $disabled_keys & "|" & "0x14" & "|"
    if $my_ESC <> "on" then $disabled_keys = $disabled_keys & "|" & "0x1B" & "|"
    if $my_SPACEBAR <> "on" then $disabled_keys = $disabled_keys & "|" & "0x20" & "|"
    if $my_PAGEUP <> "on" then $disabled_keys = $disabled_keys & "|" & "0x21" & "|"
    if $my_PAGEDOWN <> "on" then $disabled_keys = $disabled_keys & "|" & "0x22" & "|"
    if $my_END <> "on" then $disabled_keys = $disabled_keys & "|" & "0x23" & "|"
    if $my_HOME <> "on" then $disabled_keys = $disabled_keys & "|" & "0x24" & "|"
    if $my_LEFTARROW <> "on" then $disabled_keys = $disabled_keys & "|" & "0x25" & "|"
    if $my_UPARROW <> "on" then $disabled_keys = $disabled_keys & "|" & "0x26" & "|"
    if $my_RIGHTARROW <> "on" then $disabled_keys = $disabled_keys & "|" & "0x27" & "|"
    if $my_DOWNARROW <> "on" then $disabled_keys = $disabled_keys & "|" & "0x28" & "|"
    if $my_PRINT <> "on" then $disabled_keys = $disabled_keys & "|" & "0x2A" & "|"
    if $my_PRINTSCREEN <> "on" then $disabled_keys = $disabled_keys & "|" & "0x2C" & "|"
    if $my_INS <> "on" then $disabled_keys = $disabled_keys & "|" & "0x2D" & "|"
    if $my_DEL <> "on" then $disabled_keys = $disabled_keys & "|" & "0x2E" & "|"
    if $my_0 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x30" & "|"
    if $my_1 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x31" & "|"
    if $my_2 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x32" & "|"
    if $my_3 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x33" & "|"
    if $my_4 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x34" & "|"
    if $my_5 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x35" & "|"
    if $my_6 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x36" & "|"
    if $my_7 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x37" & "|"
    if $my_8 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x38" & "|"
    if $my_9 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x39" & "|"
    if $my_A <> "on" then $disabled_keys = $disabled_keys & "|" & "0x41" & "|"
    if $my_B <> "on" then $disabled_keys = $disabled_keys & "|" & "0x42" & "|"
    if $my_C <> "on" then $disabled_keys = $disabled_keys & "|" & "0x43" & "|"
    if $my_D <> "on" then $disabled_keys = $disabled_keys & "|" & "0x44" & "|"
    if $my_E <> "on" then $disabled_keys = $disabled_keys & "|" & "0x45" & "|"
    if $my_F <> "on" then $disabled_keys = $disabled_keys & "|" & "0x46" & "|"
    if $my_G <> "on" then $disabled_keys = $disabled_keys & "|" & "0x47" & "|"
    if $my_H <> "on" then $disabled_keys = $disabled_keys & "|" & "0x48" & "|"
    if $my_I <> "on" then $disabled_keys = $disabled_keys & "|" & "0x49" & "|"
    if $my_J <> "on" then $disabled_keys = $disabled_keys & "|" & "0x4A" & "|"
    if $my_K <> "on" then $disabled_keys = $disabled_keys & "|" & "0x4B" & "|"
    if $my_L <> "on" then $disabled_keys = $disabled_keys & "|" & "0x4C" & "|"
    if $my_M <> "on" then $disabled_keys = $disabled_keys & "|" & "0x4D" & "|"
    if $my_N <> "on" then $disabled_keys = $disabled_keys & "|" & "0x4E" & "|"
    if $my_O <> "on" then $disabled_keys = $disabled_keys & "|" & "0x4F" & "|"
    if $my_P <> "on" then $disabled_keys = $disabled_keys & "|" & "0x50" & "|"
    if $my_Q <> "on" then $disabled_keys = $disabled_keys & "|" & "0x51" & "|"
    if $my_R <> "on" then $disabled_keys = $disabled_keys & "|" & "0x52" & "|"
    if $my_S <> "on" then $disabled_keys = $disabled_keys & "|" & "0x53" & "|"
    if $my_T <> "on" then $disabled_keys = $disabled_keys & "|" & "0x54" & "|"
    if $my_U <> "on" then $disabled_keys = $disabled_keys & "|" & "0x55" & "|"
    if $my_V <> "on" then $disabled_keys = $disabled_keys & "|" & "0x56" & "|"
    if $my_W <> "on" then $disabled_keys = $disabled_keys & "|" & "0x57" & "|"
    if $my_X <> "on" then $disabled_keys = $disabled_keys & "|" & "0x58" & "|"
    if $my_Y <> "on" then $disabled_keys = $disabled_keys & "|" & "0x59" & "|"
    if $my_Z <> "on" then $disabled_keys = $disabled_keys & "|" & "0x5A" & "|"
    if $my_LeftWindows <> "on" then $disabled_keys = $disabled_keys & "|" & "0x5B" & "|"
    if $my_RightWindows <> "on" then $disabled_keys = $disabled_keys & "|" & "0x5C" & "|"
    if $my_Numpad0 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x60" & "|"
    if $my_Numpad1 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x61" & "|"
    if $my_Numpad2 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x62" & "|"
    if $my_Numpad3 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x63" & "|"
    if $my_Numpad4 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x64" & "|"
    if $my_Numpad5 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x65" & "|"
    if $my_Numpad6 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x66" & "|"
    if $my_Numpad7 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x67" & "|"
    if $my_Numpad8 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x68" & "|"
    if $my_Numpad9 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x69" & "|"
    if $my_NumpadMultiply <> "on" then $disabled_keys = $disabled_keys & "|" & "0x6A" & "|"
    if $my_NumpadAdd <> "on" then $disabled_keys = $disabled_keys & "|" & "0x6B" & "|"
    if $my_NumpadSeparator <> "on" then $disabled_keys = $disabled_keys & "|" & "0x6C" & "|"
    if $my_NumpadSubtract <> "on" then $disabled_keys = $disabled_keys & "|" & "0x6D" & "|"
    if $my_NumpadDecimal <> "on" then $disabled_keys = $disabled_keys & "|" & "0x6E" & "|"
    if $my_NumpadDivide <> "on" then $disabled_keys = $disabled_keys & "|" & "0x6F" & "|"
    if $my_F1 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x70" & "|"
    if $my_F2 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x71" & "|"
    if $my_F3 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x72" & "|"
    if $my_F4 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x73" & "|"
    if $my_F5 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x74" & "|"
    if $my_F6 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x75" & "|"
    if $my_F7 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x76" & "|"
    if $my_F8 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x77" & "|"
    if $my_F9 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x78" & "|"
    if $my_F10 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x79" & "|"
    if $my_F11 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x7A" & "|"
    if $my_F12 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x7B" & "|"
    if $my_F13 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x7C" & "|"
    if $my_F14 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x7D" & "|"
    if $my_F15 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x7E" & "|"
    if $my_F16 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x7F" & "|"
    if $my_F17 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x80" & "|"
    if $my_F18 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x81" & "|"
    if $my_F19 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x82" & "|"
    if $my_F20 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x83" & "|"
    if $my_F21 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x84" & "|"
    if $my_F22 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x85" & "|"
    if $my_F23 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x86" & "|"
    if $my_F24 <> "on" then $disabled_keys = $disabled_keys & "|" & "0x87" & "|"
    if $my_NUMLOCK <> "on" then $disabled_keys = $disabled_keys & "|" & "0x90" & "|"
    if $my_SCROLLLOCK <> "on" then $disabled_keys = $disabled_keys & "|" & "0x91" & "|"
    if $my_LeftSHIFT <> "on" then $disabled_keys = $disabled_keys & "|" & "0xA0" & "|"
    if $my_RightSHIFT <> "on" then $disabled_keys = $disabled_keys & "|" & "0xA1" & "|"
    if $my_LeftCONTROL <> "on" then $disabled_keys = $disabled_keys & "|" & "0xA2" & "|"
    if $my_RightCONTROL <> "on" then $disabled_keys = $disabled_keys & "|" & "0xA3" & "|"
;~ if $my_ <> "on" then $disabled_keys = $disabled_keys & "|" & "0xBA" & "|"
;~ if $my_, <> "on" then $disabled_keys = $disabled_keys & "|" & "0xBC" & "|"
;~ if $my_- <> "on" then $disabled_keys = $disabled_keys & "|" & "0xBD" & "|"
;~ if $my_. <> "on" then $disabled_keys = $disabled_keys & "|" & "0xBE" & "|"
;~ if $my_/ <> "on" then $disabled_keys = $disabled_keys & "|" & "0xBF" & "|"
;~ if $my_` <> "on" then $disabled_keys = $disabled_keys & "|" & "0xC0" & "|"
;~ if $my_[ <> "on" then $disabled_keys = $disabled_keys & "|" & "0xDB" & "|"
;~ if $my_\ <> "on" then $disabled_keys = $disabled_keys & "|" & "0xDC" & "|"
;~ if $my_] <> "on" then $disabled_keys = $disabled_keys & "|" & "0xDD" & "|"

    $disabled_keys = StringReplace($disabled_keys, "||", "|")
    if StringLeft($disabled_keys, 1) = "|" then $disabled_keys = StringTrimLeft($disabled_keys, 1)
    if StringRight($disabled_keys, 1) = "|" then $disabled_keys = StringTrimRight($disabled_keys, 1)


    _LimitInputEx(1, $disabled_keys)
;/////////////////////////////////////////////////////////////////
;//   wait for twice mouse right click to exit
;/////////////////////////////////////////////////////////////////
    While 1
        Sleep(10)
        If _IsPressed('02') Then
            If $click = 0 or $click = 1 Then
                tooltip("Another right mouse click to exit",0,0)
                sleep(250)
                tooltip("",0,0)
                $click = $click + 1
            ElseIf $click = 2 Then
                tooltip("quit",0,0)
                sleep(250)
                tooltip("",0,0)
                Exit
            EndIf
        EndIf
    WEnd


EndIf

;/////////////////////////////////////////////////////////////////
;//   function
;/////////////////////////////////////////////////////////////////
Func _assign()
    For $i = 1 To $var[0][0]
        $my_BACKSPACE = $var[1][1]
        $my_TAB = $var[2][1]
        $my_ENTER = $var[3][1]
        $SHIFT = $var[4][1]
        $my_CTRL = $var[5][1]
        $my_ALT = $var[6][1]
        $my_CAPSLOCK = $var[7][1]
        $my_ESC = $var[8][1]
        $my_SPACEBAR = $var[9][1]
        $my_PAGEUP = $var[10][1]
        $my_PAGEDOWN = $var[11][1]
        $my_END = $var[12][1]
        $my_HOME = $var[13][1]
        $my_LEFTARROW = $var[14][1]
        $my_UPARROW = $var[15][1]
        $my_RIGHTARROW = $var[16][1]
        $my_DOWNARROW = $var[17][1]
        $my_PRINT = $var[18][1]
        $my_PRINTSCREEN = $var[19][1]
        $my_INS = $var[20][1]
        $my_DEL = $var[21][1]
        $my_0 = $var[22][1]
        $my_1 = $var[23][1]
        $my_2 = $var[24][1]
        $my_3 = $var[25][1]
        $my_4 = $var[26][1]
        $my_5 = $var[27][1]
        $my_6 = $var[28][1]
        $my_7 = $var[29][1]
        $my_8 = $var[30][1]
        $my_9 = $var[31][1]
        $my_A = $var[32][1]
        $my_B = $var[33][1]
        $my_C = $var[34][1]
        $my_D = $var[35][1]
        $my_E = $var[36][1]
        $my_F = $var[37][1]
        $my_G = $var[38][1]
        $my_H = $var[39][1]
        $my_I = $var[40][1]
        $my_J = $var[41][1]
        $my_K = $var[42][1]
        $my_L = $var[43][1]
        $my_M = $var[44][1]
        $my_N = $var[45][1]
        $my_O = $var[46][1]
        $my_P = $var[47][1]
        $my_Q = $var[48][1]
        $my_R = $var[49][1]
        $my_S = $var[50][1]
        $my_T = $var[51][1]
        $my_U = $var[52][1]
        $my_V = $var[53][1]
        $my_W = $var[54][1]
        $my_X = $var[55][1]
        $my_Y = $var[56][1]
        $my_Z = $var[57][1]
        $my_LeftWindows = $var[58][1]
        $my_RightWindows = $var[59][1]
        $my_Numpad0 = $var[60][1]
        $my_Numpad1 = $var[61][1]
        $my_Numpad2 = $var[62][1]
        $my_Numpad3 = $var[63][1]
        $my_Numpad4 = $var[64][1]
        $my_Numpad5 = $var[65][1]
        $my_Numpad6 = $var[66][1]
        $my_Numpad7 = $var[67][1]
        $my_Numpad8 = $var[68][1]
        $my_Numpad9 = $var[69][1]
        $my_NumpadMultiply = $var[70][1]
        $my_NumpadAdd = $var[71][1]
        $my_NumpadSeparator = $var[72][1]
        $my_NumpadSubtract = $var[73][1]
        $my_NumpadDecimal = $var[74][1]
        $my_NumpadDivide = $var[75][1]
        $my_F1 = $var[76][1]
        $my_F2 = $var[77][1]
        $my_F3 = $var[78][1]
        $my_F4 = $var[79][1]
        $my_F5 = $var[80][1]
        $my_F6 = $var[81][1]
        $my_F7 = $var[82][1]
        $my_F8 = $var[83][1]
        $my_F9 = $var[84][1]
        $my_F10 = $var[85][1]
        $my_F11 = $var[86][1]
        $my_F12 = $var[87][1]
        $my_F13 = $var[88][1]
        $my_F14 = $var[89][1]
        $my_F15 = $var[90][1]
        $my_F16 = $var[91][1]
        $my_F17 = $var[92][1]
        $my_F18 = $var[93][1]
        $my_F19 = $var[94][1]
        $my_F20 = $var[95][1]
        $my_F21 = $var[96][1]
        $my_F22 = $var[97][1]
        $my_F23 = $var[98][1]
        $my_F24 = $var[99][1]
        $my_NUMLOCK = $var[100][1]
        $my_SCROLLLOCK = $var[101][1]
        $my_LeftSHIFT = $var[102][1]
        $my_RightSHIFT = $var[103][1]
        $my_LeftCONTROL = $var[104][1]
        $my_RightCONTROL = $var[105][1]
    ;~ $my_; = $var[106][1]
    ;~ $my_, = $var[107][1]
    ;~ $my_- = $var[108][1]
    ;~ $my_. = $var[109][1]
    ;~ $my_/ = $var[110][1]
    ;~ $my_` = $var[111][1]
    ;~ $my_[ = $var[112][1]
    ;~ $my_\ = $var[113][1]
    ;~ $my_] = $var[114][1]

    Next
;~ EndIf
    $f_go = 1
EndFunc



Func _buildini()
    local $file
    
    $file = FileOpen(@ScriptDir & "\Keybonff.ini", 2)

; Check if file opened for writing OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf

    FileWrite($file, "[Mykeyboard]" & @CRLF)
    FileWrite($file, "BACKSPACE=on" & @CRLF)
    FileWrite($file, "TAB=on" & @CRLF)
    FileWrite($file, "ENTER=on" & @CRLF)
    FileWrite($file, "SHIFT=on" & @CRLF)
    FileWrite($file, "CTRL=on" & @CRLF)
    FileWrite($file, "ALT=on" & @CRLF)
    FileWrite($file, "CAPSLOCK=on" & @CRLF)
    FileWrite($file, "ESC=on" & @CRLF)
    FileWrite($file, "SPACEBAR=on" & @CRLF)
    FileWrite($file, "PAGEUP=on" & @CRLF)
    FileWrite($file, "PAGEDOWN=on" & @CRLF)
    FileWrite($file, "END=on" & @CRLF)
    FileWrite($file, "HOME=on" & @CRLF)
    FileWrite($file, "LEFTARROW=on" & @CRLF)
    FileWrite($file, "UPARROW=on" & @CRLF)
    FileWrite($file, "RIGHTARROW=on" & @CRLF)
    FileWrite($file, "DOWNARROW=on" & @CRLF)
    FileWrite($file, "PRINT=on" & @CRLF)
    FileWrite($file, "PRINTSCREEN=on" & @CRLF)
    FileWrite($file, "INS=on" & @CRLF)
    FileWrite($file, "DEL=on" & @CRLF)
    FileWrite($file, "0=on" & @CRLF)
    FileWrite($file, "1=on" & @CRLF)
    FileWrite($file, "2=on" & @CRLF)
    FileWrite($file, "3=on" & @CRLF)
    FileWrite($file, "4=on" & @CRLF)
    FileWrite($file, "5=on" & @CRLF)
    FileWrite($file, "6=on" & @CRLF)
    FileWrite($file, "7=on" & @CRLF)
    FileWrite($file, "8=on" & @CRLF)
    FileWrite($file, "9=on" & @CRLF)
    FileWrite($file, "A=on" & @CRLF)
    FileWrite($file, "B=on" & @CRLF)
    FileWrite($file, "C=on" & @CRLF)
    FileWrite($file, "D=on" & @CRLF)
    FileWrite($file, "E=on" & @CRLF)
    FileWrite($file, "F=on" & @CRLF)
    FileWrite($file, "G=on" & @CRLF)
    FileWrite($file, "H=on" & @CRLF)
    FileWrite($file, "I=on" & @CRLF)
    FileWrite($file, "J=on" & @CRLF)
    FileWrite($file, "K=on" & @CRLF)
    FileWrite($file, "L=on" & @CRLF)
    FileWrite($file, "M=on" & @CRLF)
    FileWrite($file, "N=on" & @CRLF)
    FileWrite($file, "O=on" & @CRLF)
    FileWrite($file, "P=on" & @CRLF)
    FileWrite($file, "Q=on" & @CRLF)
    FileWrite($file, "R=on" & @CRLF)
    FileWrite($file, "S=on" & @CRLF)
    FileWrite($file, "T=on" & @CRLF)
    FileWrite($file, "U=on" & @CRLF)
    FileWrite($file, "V=on" & @CRLF)
    FileWrite($file, "W=on" & @CRLF)
    FileWrite($file, "X=on" & @CRLF)
    FileWrite($file, "Y=on" & @CRLF)
    FileWrite($file, "Z=on" & @CRLF)
    FileWrite($file, "LeftWindows=on" & @CRLF)
    FileWrite($file, "RightWindows=on" & @CRLF)
    FileWrite($file, "Numpad0=on" & @CRLF)
    FileWrite($file, "Numpad1=on" & @CRLF)
    FileWrite($file, "Numpad2=on" & @CRLF)
    FileWrite($file, "Numpad3=on" & @CRLF)
    FileWrite($file, "Numpad4=on" & @CRLF)
    FileWrite($file, "Numpad5=on" & @CRLF)
    FileWrite($file, "Numpad6=on" & @CRLF)
    FileWrite($file, "Numpad7=on" & @CRLF)
    FileWrite($file, "Numpad8=on" & @CRLF)
    FileWrite($file, "Numpad9=on" & @CRLF)
    FileWrite($file, "NumpadMultiply=on" & @CRLF)
    FileWrite($file, "NumpadAdd=on" & @CRLF)
    FileWrite($file, "NumpadSeparator=on" & @CRLF)
    FileWrite($file, "NumpadSubtract=on" & @CRLF)
    FileWrite($file, "NumpadDecimal=on" & @CRLF)
    FileWrite($file, "NumpadDivide=on" & @CRLF)
    FileWrite($file, "F1=on" & @CRLF)
    FileWrite($file, "F2=on" & @CRLF)
    FileWrite($file, "F3=on" & @CRLF)
    FileWrite($file, "F4=on" & @CRLF)
    FileWrite($file, "F5=on" & @CRLF)
    FileWrite($file, "F6=on" & @CRLF)
    FileWrite($file, "F7=on" & @CRLF)
    FileWrite($file, "F8=on" & @CRLF)
    FileWrite($file, "F9=on" & @CRLF)
    FileWrite($file, "F10=on" & @CRLF)
    FileWrite($file, "F11=on" & @CRLF)
    FileWrite($file, "F12=on" & @CRLF)
    FileWrite($file, "F13=on" & @CRLF)
    FileWrite($file, "F14=on" & @CRLF)
    FileWrite($file, "F15=on" & @CRLF)
    FileWrite($file, "F16=on" & @CRLF)
    FileWrite($file, "F17=on" & @CRLF)
    FileWrite($file, "F18=on" & @CRLF)
    FileWrite($file, "F19=on" & @CRLF)
    FileWrite($file, "F20=on" & @CRLF)
    FileWrite($file, "F21=on" & @CRLF)
    FileWrite($file, "F22=on" & @CRLF)
    FileWrite($file, "F23=on" & @CRLF)
    FileWrite($file, "F24=on" & @CRLF)
    FileWrite($file, "NUMLOCK=on" & @CRLF)
    FileWrite($file, "SCROLLLOCK=on" & @CRLF)
    FileWrite($file, "LeftSHIFT=on" & @CRLF)
    FileWrite($file, "RightSHIFT=on" & @CRLF)
    FileWrite($file, "LeftCONTROL=on" & @CRLF)
    FileWrite($file, "RightCONTROL=on")

    FileClose($file)
    
EndFunc

Func Terminate()
    Exit 0
EndFunc

now script accept its default .ini with on/off for single key,

via command line accept user .ini for manage different 'profiles',

press twice right mouse button to exit

thank you ken82 for your work.

m.

PS:

miss ; , - . / ` [ \ ] because i don't know right english 'names' for these symbols, can anyone post them ?

Link to comment
Share on other sites

The following hotkeys cannot be blocked or modified.

Ctrl+Alt+Delete It is reserved by Windows

F12 It is also reserved by Windows, according to its API.

NumPad's Enter Key Instead, use {Enter} which captures both Enter keys on the keyboard.

Win+B,D,E,F,L,M,R,U; and Win+Shift+M These are built-in Windows shortcuts. Note: Win+B and Win+L might only be reserved on Windows XP and above.

Alt, Ctrl, Shift, Win These are the modifier keys themselves!

Other Any global hotkeys a user has defined using third-party software, any combos of two or more "base keys" such as '{F1}{F2}', and any keys of the form '{LALT}' or '{ALTDOWN}'.

and your script will not work for these. right?

Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.
Link to comment
Share on other sites

  • 2 weeks later...

@ken82m

Dont take it out on me, Ive added some functions to your script (got ideas from IsPressed_UDF)

#cs ----------------------------------------------------------------------------
Function:     _LimitInputEx
Author:       Kenneth P. Morrissey
Based on:     _BlockInputEx() by Rasim and MrCreatoR

Script Function:
    This function limits keyboard input to keys specified.

--------------------------------------------------------------------------------

_LimitInputEx ( $sBlock = 0 , [ sExclude = ""  , [ $sALTExclude = "" ]] )

Parameters
$sBlock:            0 = Unblock(Default)
                    1 = Block

sExclude:           List of key(s) to be blocked
                        List of keys should be in quotes
                        For multiple keys separate them with |
                        For example: "0x1B|0x70|0x71|0x72|0x73"

sALTExclude:           List of key(s) combined with ALT to be blocked
                        List of keys should be in quotes
                        For multiple keys separate them with |
                        For example: "0x09|0x73" would block ALT-TAB and ALT-F4

Return Value:        Success: Returns 1
                    Failure: Returns 0
                        Sets @error to 1

Remarks:            Ctrl+Alt+Del cannot be blocked due to a Windows API feature.

Operating System "_LimitInputEx" Results
Windows 95:    Not tested, probably won't work.
Windows 98/Me: Not tested, probably won't work.
Windows NT 4:  User input is blocked and AutoIt can simulate most input.
Windows 2000:  User input is blocked and AutoIt can simulate most input.
Windows XP:    User input is blocked and AutoIt can simulate most input.
Windows Vista: User input is blocked and AutoIt can simulate most input.
___________________________________

Key List:
08   BACKSPACE key
09   TAB key
0D   ENTER key
10   SHIFT key
11   CTRL key
12   ALT key
14   CAPS LOCK key
1B   ESC key
20   SPACEBAR
21   PAGE UP key
22   PAGE DOWN key
23   END key
24   HOME key
25   LEFT ARROW key
26   UP ARROW key
27   RIGHT ARROW key
28   DOWN ARROW key
2A   PRINT key
2C   PRINT SCREEN key
2D   INS key
2E   DEL key
30   0 key
31   1 key
32   2 key
33   3 key
34   4 key
35   5 key
36   6 key
37   7 key
38   8 key
39   9 key
41   A key
42   B key
43   C key
44   D key
45   E key
46   F key
47   G key
48   H key
49   I key
4A   J key
4B   K key
4C   L key
4D   M key
4E   N key
4F   O key
50   P key
51   Q key
52   R key
53   S key
54   T key
55   U key
56   V key
57   W key
58   X key
59   Y key
5A   Z key
5B   Left Windows key
5C   Right Windows key
60   Numeric keypad 0 key
61   Numeric keypad 1 key
62   Numeric keypad 2 key
63   Numeric keypad 3 key
64   Numeric keypad 4 key
65   Numeric keypad 5 key
66   Numeric keypad 6 key
67   Numeric keypad 7 key
68   Numeric keypad 8 key
69   Numeric keypad 9 key
6A   Numpad Multiply key
6B   Numpad Add key
6C   Numpad Separator key
6D   Numpad Subtract key
6E   Numpad Decimal key
6F   Numpad Divide key
70   F1 key
71   F2 key
72   F3 key
73   F4 key
74   F5 key
75   F6 key
76   F7 key
77   F8 key
78   F9 key
79   F10 key
7A   F11 key
7B   F12 key
7C   F13 key
7D   F14 key
7E   F15 key
7F   F16 key
80   F17 key
81   F18 key
82   F19 key
83   F20 key
84   F21 key
85   F22 key
86   F23 key
87   F24 key
90   NUM LOCK key
91   SCROLL LOCK key
A0   Left SHIFT key
A1   Right SHIFT key
A2   Left CONTROL key
A3   Right CONTROL key
BA  ;
BB   =
BC   ","
BD   -
BE   .
BF   /
C0   `
DB   [
DC   \
DD   ]
___________________________________
    _Multikey examples :
    Block All _Multikey(1, 221)
    Block Alpha _Multikey(48, 90)
    Block Num _Multikey(96, 105)
    Block AlphaNum _Multikey(65, 105)
    Block Func _Multikey(112, 123)
               _Multikey(124, 135)
    Block Arrow _Multikey(37, 40)
    Block Mouse _Multikey(1, 6)
    Block other keys _Multikey(8, 36)
                     _Multikey(41, 46)
                     _Multikey(91, 92)
                     _Multikey(106, 111)
                     _Multikey(136, 165)
___________________________________

Example of using this UDF:
   #Include <LimitInputEx.au3>

   _LimitInputEx(1, "1B|70|71|72|73");1B={ESC},70="{F1}",71="{F2}",72="{F3}",73="{F4}"

    AdlibEnable("OnAutoITExit", 10000);This is only for testing, so if anything go wrong, the script will exit after 10 seconds.

   While 1
       Sleep(100)
   WEnd

   Func OnAutoITExit()
       _LimitInputEx()
   EndFunc
#ce ----------------------------------------------------------------------------

#include <IsPressed_UDF.au3>
#include <WinAPI.au3>

Global $ah_Hooks
Global $ah_Hooks2

Func _LimitInputEx($sBlock = 0, $sExclude = '', $sALTExclude = '')
    Select
        Case IsArray($ah_Hooks) And $sBlock = 0
            If $ah_Hooks[1] > 0 Then DllCallbackFree($ah_Hooks[1])
            If $ah_Hooks[2] > 0 Then DllCallbackFree($ah_Hooks[2])

            If $ah_Hooks[3] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_Hooks[3])
            If $ah_Hooks[4] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_Hooks[4])
            Return 1

        Case IsArray($ah_Hooks) And $sBlock = 1
            If $ah_Hooks[1] > 0 Then DllCallbackFree($ah_Hooks[1])
            If $ah_Hooks[2] > 0 Then DllCallbackFree($ah_Hooks[2])

            If $ah_Hooks[3] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_Hooks[3])
            If $ah_Hooks[4] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_Hooks[4])

        Case IsNumber($sBlock) And $sBlock > 0
            Local $pStub_KeyProc = 0, $hHookKeyboard = 0

            $pStub_KeyProc = DllCallbackRegister("_Key_Proc", "int", "int;ptr;ptr")
            $hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _
                    _WinAPI_GetModuleHandle(0), 0)

            Local $aRet[5] = ["|0x" & $sExclude & "|", $pStub_KeyProc, $hHookKeyboard]
            Global $ah_Hooks2 = "|" & $sALTExclude & "|"

            Global $ah_Hooks
            $ah_Hooks = $aRet
            Return 1
        Case Else
            Return SetError(1, 0, 0)
    EndSelect
EndFunc   ;==>_LimitInputEx

Func _Key_Proc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($ah_Hooks[3], $nCode, $wParam, $lParam)

    Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)
    Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")
    Local $flags = DllStructGetData($KBDLLHOOKSTRUCT, "flags")
    ;Local $scanCode = DllStructGetData($KBDLLHOOKSTRUCT, "scanCode")

    ;Disable ALT-TAB
    If $flags = $LLKHF_ALTDOWN And StringInStr($ah_Hooks2, "|0x" & Hex($vkCode, 2) & "|") Then Return 1
    If StringInStr($ah_Hooks[0], "|0x" & Hex($vkCode, 2) & "|") Then Return 1
    _WinAPI_CallNextHookEx($ah_Hooks[3], $nCode, $wParam, $lParam)
EndFunc   ;==>_Key_Proc


; #FUNCTION# ===================================================================
; Name :            _Multikey
; Description:      Returns hex key of specified number start and finish
; Parameter(s):     None
; Requirement(s):   None
; Return Value(s):  On Success - Returns hex
;                   On Failure - Returns -1
; Author(s):        FireFox
; Note(s):          None
;===============================================================================
Func _Multikey($Start = 0, $End = 0)
    Local $key

    For $hex = $Start To $End
        If Not @error Then $key = $key & Hex($hex, 2) & '|'
    Next
    If $key <> '' Then
        Return $key
    EndIf

    Return -1
EndFunc   ;==>_Multikey

Examples :

_LimitInputEx with Hex :

#include <LimitInputEx.au3>

_LimitInputEx(1, "0D");Block ENTER


While 1
    Sleep(100)
WEnd

Func OnAutoItExit()
    _LimitInputEx()
EndFunc  ;==>OnAutoITExit

_LimitInputEx with Alpha :

#include <LimitInputEx.au3>

_LimitInputEx(1, __GetKeyType("ENTER",1));Block ENTER


While 1
    Sleep(100)
WEnd

Func OnAutoItExit()
    _LimitInputEx()
EndFunc  ;==>OnAutoITExit

_LimitInputEx with functions keys :

#include <LimitInputEx.au3>

_LimitInputEx(1, _MultiKey(112, 123)&_MultiKey(124, 135));Block function keys

While 1
    Sleep(100)
WEnd

Func OnAutoItExit()
    _LimitInputEx()
EndFunc  ;==>OnAutoItExit
Link to comment
Share on other sites

  • 2 years later...

Added parameter to block ALT+KEY combinations.

First off, many thanks for doing this! Your UDF is extremely powerful. Great stuff! Blocking the Win Key even works on Windows 7! That is so awesome!

What code should I use if I want to disalbe the Alt+Tab combination without disabling the Alt or Tab individual keys?

Does anybody know how to do this?

Thanks!

Ian

EDIT: Never mind. I got it. It's in the examples that came with the UDF.

Edited by intime69

Developer and Co-OwnerInTime Applicaitons Inc.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...