Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

BlockInputEx UDF!


  • Please log in to reply
66 replies to this topic

#1 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 15 January 2009 - 01:53 PM

Hi,

This UDF originaly started in this thread, on the latest post you can find rasim's examples and my initial BlockInputEx udf example. But eventualy i improved the UDF and i thought that it would be better to place it here, in Examples forum.

This UDF supports few features that built-in BlockInput() function does not.
Here is a quick "features list" if you can call it like this :):

  • Block seperately mouse or keyboard input.
  • Block specific keyboard/mouse keys/clicks.
    [+] Not only hex keys are supported, string keys (such as {ENTER}) is also valid.
  • Block all keyboard/mouse keys *except* specific keys/events.
  • Block keys by CLASS Name (see UDF documentation).
  • Block inputs only for specific window.
  • BlockInput does not re-enables input after pressing Ctrl+Alt+Del.

Note: This UDF, same as built-in BlockInput function, can not block Ctrl+Alt+Del, however, it will not re-enable the input.

 

Example #1 (hWindows usage):

AutoIt         
#include <BlockInputEx.au3> ;================== hWindows usage Example ================== HotKeySet("{ESC}", "_Quit") ;This will trigger an exit (on any window except the window of Notepad). Run(@WindowsDir & "\Notepad.exe", "", @SW_MAXIMIZE) WinWait("[REGEXPCLASS:Notepad.*]") $hNotepad_Wnd = WinGetHandle("[REGEXPCLASS:Notepad.*]") ControlSetText($hNotepad_Wnd, "", "", _     "Now try to input some keys in here..." & @CRLF & _     "Well, that's the idea, you can't, don't you?" & @CRLF & @CRLF & ":)") ;Here we block *All* keyboard keys for specific window (in this case the Notepad's window). _BlockInputEx(3, "", "", $hNotepad_Wnd) ;This is only for testing, so if anything go wrong, the script will exit after 10 seconds. AdlibRegister("_Quit", 10000) While 1     Sleep(100) WEnd Func _Quit()     Exit EndFunc

Example #2 (CLASSes usage):

#include <BlockInputEx.au3> ;================== CLASSes usage Example ================== HotKeySet("{ESC}", "_Quit");This will trigger an exit ;Here we block Numeric keyboard keys, "Test" string (every char in this group), and UP / DOWN arrow keys. _BlockInputEx(3, "", "[:NUMBER:]|[Test]|{UP}|{DOWN}") ;This is only for testing, so if anything go wrong, the script will exit after 10 seconds. AdlibRegister("_Quit", 10000) While 1     Sleep(100) WEnd Func _Quit()     Exit EndFunc

Download (In the archive there is 11 nice examples including the two above):
Attached File  BlockInputEx_UDF_1.8.zip   10.78KB   1218 downloads
Attached File  BlockInputEx_UDF_1.6.zip   10.43KB   1821 downloads
Attached File  _BlockInputEx_UDF_1.5.zip   10.11KB   613 downloads
Attached File  _BlockInputEx_UDF_1.4.zip   9.71KB   597 downloads
Attached File  _BlockInputEx_UDF_1.3.zip   8.77KB   952 downloads
Attached File  _BlockInputEx_UDF_1.2.zip   8.14KB   803 downloads
Attached File  _BlockInputEx_UDF_1.1.zip   6.01KB   463 downloads
Attached File  _BlockInputEx_UDF.zip   4.68KB   505 downloads


Enjoy! coffee.gif

=================================================================

ChangeLog:

Spoiler

Edited by MrCreatoR, 12 May 2013 - 09:31 AM.

  • mLipok, yahaosoft, lancebh and 1 other like this
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team








#2 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,375 posts

Posted 15 January 2009 - 01:55 PM

@MrCreator
Nice one :) I will add some functions to this udf

Cheers, FireFox.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#3 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,375 posts

Posted 15 January 2009 - 07:37 PM

@MrCreator

UDF :
AutoIt         
#include-once #include <WindowsConstants.au3> #include <WinAPI.au3> ; #Region ======================== BlockInputEx UDF Info ======================== ; Extended (advanced) function to block mouse & keyboard inputs. ; ; AutoIt Version: 3.2.12.1+ ; Author: G.Sandler (a.k.a MrCreatoR). Initial idea and hooks example by rasim. #EndRegion ======================== BlockInputEx UDF Info ======================== ; Global $ah_MouseKeyboard_WinHooks[7] ; #FUNCTION# ==================================================================================================== ================ ; Name...........: _BlockInputEx ; Description ...: Disable/enable the mouse and/or keyboard. Supporting blocking (by include/exclude) of seperate keys. ; Syntax.........: _BlockInputEx( [iBlockMode [, sExclude [, sInclude [, hWindows]]]] ) ; Parameters ....: $iBlockMode - Set the block mode. -1 = UnBlock all ;                                        1 = Block All ;                                        2 = Block only mouse ;                                        3 = Block only keyboard ;                                        4 = Block only func keys ;                                        5 = Block only alpha keys ;                                        6 = Block only numeric keys ;                                        7 = Block only arrow keys ;                                        8 = Block only special keys ;                  $sExclude   - Keys hex-list (| delimited) to *exclude* when blocking (Only for keyboard blocking). ;                                 [*] All keys will be blocked, except the keys in $sExclude list. ;                                 [!] The hex keys list can be found in _IsPressed documentation section. ;                          [/] For $iBlockMode = 4 to 8, $sExclude will be enable for 1 / disabled for <> 1 ;                  $sInclude   - Keys hex-list (| delimited) to *include* when blocking (Only for keyboard blocking). ;                                 [*] Only these keys will be blocked, the $sExclude ignored in this case. ;                                 [!] The hex keys list can be found in _IsPressed documentation section. ;                          [/] For $iBlockMode = 4 to 8, $sInclude will be enable for 1 / disabled for <> 1 ;                  $hWindows   - Window handles list (| delimited) to limit the blocking process (Only for keyboard blocking). ; Return values .: Success     - 1. ;                  Failure     - 0 and set @error to 1. This can happend only when passing wrong parameters. ; Author(s)......: Rasim, MrCreator, FireFox ; Modified.......: MrCreator (15/01/09) ; FireFox (15/01/09) ; Remarks .......: This UDF includes OnAutoItExit function to release the callback/hooks resources. ;                    [*] See also native BlockInput() documentation. ; Related .......: BlockInput? ; ==================================================================================================== =========================== Func _BlockInputEx($iBlockMode = -1, $sExclude = '', $sInclude = '', $hWindows = '')     If $iBlockMode < -1 Or $iBlockMode > 8 Then Return SetError(1, 0, 0) ;Only -1, 0, 1 and 2 modes are supported.         If $iBlockMode = -1 Then Return _BlockInput_UnhookWinHooks_Proc()         Local $pStub_KeyProc = 0, $pStub_MouseProc = 0, $hHook_Keyboard = 0, $hHook_Mouse = 0     Local $hHook_Module = _WinAPI_GetModuleHandle(0)         For $i = 0 To 3         If $ah_MouseKeyboard_WinHooks[$i] > 0 Then             _BlockInput_UnhookWinHooks_Proc()             ExitLoop         EndIf     Next         If $iBlockMode = 1 Or $iBlockMode = 2 Then         $pStub_MouseProc = DllCallbackRegister("_MouseHook_Proc", "int", "int;ptr;ptr")         $hHook_Mouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($pStub_MouseProc), $hHook_Module, 0)     EndIf         If $iBlockMode = 1 Or $iBlockMode = 3 Then         $pStub_KeyProc = DllCallbackRegister("_KeyBoardHook_Proc", "int", "int;ptr;ptr")         $hHook_Keyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), $hHook_Module, 0)     ElseIf $iBlockMode = 4 Then         $pStub_KeyProc = DllCallbackRegister("_KeyBoardHook_Proc", "int", "int;ptr;ptr")         $hHook_Keyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), $hHook_Module, 0)         If $sExclude = 1 Then             $sExclude = '0x70|0x71|0x72|0x73|0x74|0x75|0x76|0x77|0x78|0x79|0x7A|0x7B|0x7C|0x7D|0x7E|0x7F' & _                     '|0x80H|0x81H|0x82H|0x83H|0x84H|0x85H|0x86H|0x87H'         ElseIf $sInclude = 1 Then             $sInclude = '0x70|0x71|0x72|0x73|0x74|0x75|0x76|0x77|0x78|0x79|0x7A|0x7B|0x7C|0x7D|0x7E|0x7F' & _                     '|0x80H|0x81H|0x82H|0x83H|0x84H|0x85H|0x86H|0x87H'         EndIf     ElseIf $iBlockMode = 5 Then         $pStub_KeyProc = DllCallbackRegister("_KeyBoardHook_Proc", "int", "int;ptr;ptr")         $hHook_Keyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), $hHook_Module, 0)         If $sExclude = 1 Then             $sExclude = '0x41|0x42|0x43|0x44|0x45|0x46|0x47|0x48|0x49|0x4A|0x4B|0x4C|0x4D|0x4E|0x4F|0x50' & _                     '|0x51|0x52|0x53|0x54|0x55|0x56|0x57|0x58|0x59|0x5A'         ElseIf $sInclude = 1 Then             $sInclude = '0x41|0x42|0x43|0x44|0x45|0x46|0x47|0x48|0x49|0x4A|0x4B|0x4C|0x4D|0x4E|0x4F|0x50' & _                     '|0x51|0x52|0x53|0x54|0x55|0x56|0x57|0x58|0x59|0x5A'         EndIf     ElseIf $iBlockMode = 6 Then         If $sExclude = 1 Then             $sExclude = '0x30|0x31|0x32|0x33|0x34|0x35|0x36|0x37|0x38|0x39|0x60|0x61|0x62|0x63|0x64|0x65' & _                     '|0x66|0x67|0x68|0x69'         ElseIf $sInclude = 1 Then             $sInclude = '0x30|0x31|0x32|0x33|0x34|0x35|0x36|0x37|0x38|0x39|0x60|0x61|0x62|0x63|0x64|0x65' & _                     '|0x66|0x67|0x68|0x69'         EndIf     ElseIf $iBlockMode = 7 Then         If $sExclude = 1 Then             $sExclude = '0x25|0x26|0x27|0x28'         ElseIf $sInclude = 1 Then             $sInclude = '0x25|0x26|0x27|0x28'         EndIf     ElseIf $iBlockMode = 8 Then         If $sExclude = 1 Then             $sExclude = '0x08|0x09|0x0C|0x0D|0x10|0x11|0x12|0x13|0x14|0x1B|0x20|0x21|0x22|0x23|0x24' & _                     '|0x29|0x2A|0x2B|0x2C|0x2D|0x2E|0x5B|0x5C|0x6A|0x6B|0x6C|0x6D|0x6E|0x6F|0x90|0x91|0xA0' & _                     '|0xA1|0xA2|0xA3|0xA4|0xA5|0xBA|0xBB|0xBC|0xBD|0xBE|0xBF|0xC0|0xDB|0xDC|0xDD'         ElseIf $sInclude = 1 Then             $sInclude = '0x08|0x09|0x0C|0x0D|0x10|0x11|0x12|0x13|0x14|0x1B|0x20|0x21|0x22|0x23|0x24' & _                     '|0x29|0x2A|0x2B|0x2C|0x2D|0x2E|0x5B|0x5C|0x6A|0x6B|0x6C|0x6D|0x6E|0x6F|0x90|0x91|0xA0' & _                     '|0xA1|0xA2|0xA3|0xA4|0xA5|0xBA|0xBB|0xBC|0xBD|0xBE|0xBF|0xC0|0xDB|0xDC|0xDD'         EndIf     EndIf         $ah_MouseKeyboard_WinHooks[0] = $pStub_KeyProc     $ah_MouseKeyboard_WinHooks[1] = $pStub_MouseProc     $ah_MouseKeyboard_WinHooks[2] = $hHook_Keyboard     $ah_MouseKeyboard_WinHooks[3] = $hHook_Mouse     $ah_MouseKeyboard_WinHooks[4] = "|" & $sInclude & "|"     $ah_MouseKeyboard_WinHooks[5] = "|" & $sExclude & "|"     $ah_MouseKeyboard_WinHooks[6] = "|" & $hWindows & "|"         Return 1 EndFunc   ;==>_BlockInputEx ;KeyBoard hook processing function Func _KeyBoardHook_Proc($nCode, $wParam, $lParam)     If $nCode < 0 Then Return _WinAPI_CallNextHookEx($ah_MouseKeyboard_WinHooks[4], $nCode, $wParam, $lParam)         Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)     Local $vkCode = "0x" & Hex(DllStructGetData($KBDLLHOOKSTRUCT, "vkCode"), 2)         Local $sInclude = $ah_MouseKeyboard_WinHooks[4]     Local $sExclude = $ah_MouseKeyboard_WinHooks[5]     Local $hWnds = $ah_MouseKeyboard_WinHooks[6]         If $sInclude <> "||" Then ;Include proc         If StringInStr($sInclude, "|" & $vkCode & "|") And _                 ($hWnds = "||" Or StringInStr($hWnds, "|" & WinGetHandle("[ACTIVE]") & "|")) Then Return 1 ;Block processing!     Else ;Exclude proc         If Not StringInStr($sExclude, "|" & $vkCode & "|") And _                 ($hWnds = "||" Or StringInStr($hWnds, "|" & WinGetHandle("[ACTIVE]") & "|")) Then Return 1 ;Block processing!     EndIf         _WinAPI_CallNextHookEx($ah_MouseKeyboard_WinHooks[2], $nCode, $wParam, $lParam) ;Continue processing EndFunc   ;==>_KeyBoardHook_Proc ;Mouse hook processing function Func _MouseHook_Proc($nCode, $wParam, $lParam)     If $nCode < 0 Then Return _WinAPI_CallNextHookEx($ah_MouseKeyboard_WinHooks[3], $nCode, $wParam, $lParam) ;Continue processing         Return 1 ;Block processing! EndFunc   ;==>_MouseHook_Proc ;Releases callbacks and Unhook Windows hooks Func _BlockInput_UnhookWinHooks_Proc()     If $ah_MouseKeyboard_WinHooks[0] > 0 Then DllCallbackFree($ah_MouseKeyboard_WinHooks[0])     If $ah_MouseKeyboard_WinHooks[1] > 0 Then DllCallbackFree($ah_MouseKeyboard_WinHooks[1])         If $ah_MouseKeyboard_WinHooks[2] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_MouseKeyboard_WinHooks[2])     If $ah_MouseKeyboard_WinHooks[3] > 0 Then _WinAPI_UnhookWindowsHookEx($ah_MouseKeyboard_WinHooks[3])         For $i = 0 To 3         $ah_MouseKeyboard_WinHooks[$i] = 0     Next         Return 1 EndFunc   ;==>_BlockInput_UnhookWinHooks_Proc ;Called when script exits to release resources. Func OnAutoItExit()     _BlockInputEx(0) EndFunc   ;==>OnAutoItExitƒo݊÷ ØLZš™^jëhŠ×6#include <BlockInputEx.au3> ;================== hWindows usage Example ================== HotKeySet("{ESC}", "_Quit") ;This will trigger an exit ;Here we block alphabetic keyboard keys : _BlockInputEx(5, 0, 1) ;This is only for testing, so if anything go wrong, the script will exit after 10 seconds. AdlibEnable("_Quit", 10000) While 1     Sleep(100) WEnd Func _Quit()     Exit EndFunc

Cheers, FireFox.

Edited by FireFox, 18 January 2009 - 11:59 AM.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#4 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 15 January 2009 - 07:45 PM

MrCreator, Thank you! :)

This is perfect because I need lock out my mouse and keyboard whenever my niece comes over to watch movies.
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#5 RWBaker

RWBaker

    Seeker

  • Active Members
  • 19 posts

Posted 16 January 2009 - 01:18 AM

I must be missing something...execution stops when I respond to the first MsgBox below??
Can you help?

RWBaker

#include <BlockInputEx.au3> MsgBox(0,"","Start blocking for 5 seconds...") _BlockInputEx(-1) Sleep(5000) _BlockInputEx(0) MsgBox(0,"","Input unblocked now.") ; execution is terminated after response to this statement??? MsgBox(0,"","Input unblocked now 2.") ; this statement is not executed??? Exit

RW Baker

#6 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 16 January 2009 - 01:15 PM

Update!

History version:

[v1.1 - 16.01.2009]
+ Added CLASSes support (see UDF documentation), thanks to FireFox for the idea and the keys lists.
+ Added example for CLASS usage.
* Changed behaviour of $iBlockMode parameter as following:

1  - Block All <= 0  - UnBlock all 2  - Block only mouse 3  - Block only keyboard.


* Fixed hard-crash that related to incorrect BlockInput releasing process (only callbacks was released, not the window hooks).

[v1.0 - 15.01.2009]
First release.


Please check the first post.

Edited by MrCreatoR, 16 January 2009 - 01:16 PM.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#7 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,375 posts

Posted 16 January 2009 - 04:20 PM

@MrCreator
Have you seen my reply ?

Cheers, FireFox.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#8 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 16 January 2009 - 05:40 PM

@MrCreator
Have you seen my reply ?

Cheers, FireFox.

Sure i have, how then i could add the classes support? :) If you got the last UDF version you could notice it :lmao: - Thanks.

P.S
I am working on a new version, where we can set as include/exclude parameters a simple key strings (such as {Enter}, or even a Group like in RegExpReplace, i.e: "[Test]", here the chars t,e and s will be included/excluded when blocking).
I also want to add a support for Mouse events blocking, different mouse buttons and whell scrolling...
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#9 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,375 posts

Posted 16 January 2009 - 06:28 PM

@MrCreator
Thanks, keep it up as you said :)

Cheers, FireFox.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#10 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 16 January 2009 - 07:14 PM

I am working on a new version, where we can set as include/exclude parameters a simple key strings (such as {Enter}, or even a Group like in RegExpReplace, i.e: "[Test]", here the chars t,e and s will be included/excluded when blocking).
I also want to add a support for Mouse events blocking, different mouse buttons and whell scrolling...

Done!

History Version:

[v1.2 - 16.01.2009, 21:00]
+ Added key strings support.
--Now users can set simple hotkey strings for Exclude/Include parameters + Group chars, i.e: "[Group]|{UP}|{DOWN}"
---(See UDF documentation)
+ Added mouse events blocking support to the $sExclude/$sInclude parameters.
+ Added example for mouse events blocking.

P.S
I think it's a last one for today :)

Edited by MrCreatoR, 16 January 2009 - 07:17 PM.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#11 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,375 posts

Posted 16 January 2009 - 09:28 PM

@MrCreator
I think nothing can be done now for keyboard after this udf and IsPressed_UDF :)

Cheers, FireFox.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#12 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 25 January 2009 - 02:23 PM

There is a mistake in the «_BlockInputEx Example (Block ALL, standard usage).au3», where _BlockInputEx(-1) should be _BlockInputEx(1). I will fix that with the next update.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#13 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,375 posts

Posted 25 January 2009 - 02:44 PM

@MrCreatoR
I fixed that in my example :)

Cheers, FireFox.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#14 elemirac

elemirac

    Seeker

  • New Members
  • 3 posts

Posted 03 July 2009 - 09:40 PM

Hello all!
I have one suggestion that can be usefull to all:
How about a password for unlocking?
I've tried to do it, but no luck (yet)... General idea is to display input box asking for password when unlocking, but problem is that you have to unlock keyboard in order to type the pass, but do not let the user go away from input box untill the pass is correct...

any ideas?

#15 elemirac

elemirac

    Seeker

  • New Members
  • 3 posts

Posted 06 July 2009 - 03:58 PM

OK, I managed to solve thisone myself. Here is my code for Keyboard and mouse lock that requires password to unlock. This code may need some optimizing but it works fine. (I used the code from previous thread and modified it)
When the program starts it writes date and time of start in log file, and waits for 10 seconds of idle time to lock keyboard and mouse. When they are locked splash screen is displayed. If you want to unlock you must press PAUSE key (which I used because it is all the way in the corner and can't be missed), and after that type the password. If the usual pass is typed then all is unlocked but the program still counts idle time and will lock all again after 10 seconds, but if you type special secret pass, then all is unlocked and program exits.
Program writes to log file each time someone unlocks or locks PC, or if someone attempts to unlock and types the wrong pass.
That's about it, the rest you can see from the code.

CODE
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=lockPC.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <WinAPI.au3>
#include <Timers.au3>
#include <Date.au3>

Opt("TrayMenuMode", 1)
Opt("WinTitleMatchMode", 2)

HotKeySet("{PAUSE}", "_UnBlock")

; Values
;-------
$idleTimeValue = 10000 ; Idle time to wait until lock
$validPass = "pass" ; This password unlocks all, but program still counts idle time and will lock all again if there's no user input
$ultimatePass = "secret" ; With this password all is unlocked and program exits
$iniFile = "C:\lockPC.log" ; Location and name of log file


IniWrite($iniFile, @ComputerName & " - Log", _Now(), "Program started")

; This is the initial idle time check, after this IDLE time PC is locked
;-----------------------------------------------------------------------
while 1
if _Timer_GetIdleTime()<$idleTimeValue Then
ContinueLoop
Else
ExitLoop
EndIf
WEnd

Global $pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
Global $pStub_MouseProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr")


Global $hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0)
Global $hHookMouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($pStub_MouseProc), _WinAPI_GetModuleHandle(0), 0)


SplashTextOn ( "Lock", "Keyboard and mouse locked!" & @LF & @LF & "Press PAUSE key to unlock",300,100,20,-1,1,"",14,200)
for $anim = 0 to 360
WinSetTrans("Lock","",$anim/2)
Next
IniWrite($iniFile, @ComputerName & " - Log", _Now(), "PC Locked")

While 1
Sleep(100)
WEnd


; Func _UnBlock runs password check and unlocks only keys needed for password input
;----------------------------------------------------------------------------------
Func _UnBlock()
for $anim = 360 to 0 step -1
WinSetTrans("Lock","",$anim/2)
Next
SplashOff()

DllCallbackFree($pStub_KeyProc)
_WinAPI_UnhookWindowsHookEx($hHookKeyboard)

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

$password = InputBox("UnBlock", "Enter the password", "", "*8",-1,130)


; Password check
;----------------
if $password = $validPass Then
call("_unlockAll")
IniWrite($iniFile, @ComputerName & " - Log", _Now(), "PC Unlocked")
while 1

; Again idle time check, after this IDLE time PC is locked
;----------------------------------------------------------
if _Timer_GetIdleTime()<$idleTimeValue Then
ContinueLoop
Else
call("_unlockAll")
call("_block")
IniWrite($iniFile, @ComputerName & " - Log", _Now(), "PC Locked")
SplashTextOn ( "Lock", "Keyboard and mouse locked!" & @LF & @LF & "Press PAUSE key to unlock",300,100,20,-1,1,"",14,200)
for $anim = 0 to 360
WinSetTrans("Lock","",$anim/2)
Next
ExitLoop
EndIf
WEnd
;Exit
ElseIf $password = $ultimatePass Then
call("_unlockAll")
IniWrite($iniFile, @ComputerName & " - Log", _Now(), "Secret Password - Program end")
Exit
else
call("_unlockAll")
call("_block")
IniWrite($iniFile, @ComputerName & " - Log", _Now(), "Unlock Attempt - Wrong password")
SplashTextOn ( "Lock", "Keyboard and mouse locked!" & @LF & @LF & "Press PAUSE key to unlock",300,100,20,-1,1,"",14,200)
for $anim = 0 to 360
WinSetTrans("Lock","",$anim/2)
Next
EndIf
EndFunc

; Func _KeyProc determines which keys are locked - $vkCode <> values are keys that are UNLOCKED (Pause key [0x13] and ENTER [0x0D])
;----------------------------------------------------------------------------------------------------------------------------------
Func _KeyProc($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)

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

If $vkCode <> 0x13 and $vkCode <> 0x0D Then Return 1

_WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)
EndFunc

Func _Mouse_Handler($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookMouse, $nCode, $wParam, $lParam)

Return 1
EndFunc

; Func _block is locking everything
;----------------------------------
Func _block()
$pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
$pStub_MouseProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr")
$hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0)
$hHookMouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($pStub_MouseProc), _WinAPI_GetModuleHandle(0), 0)
EndFunc


; Func _noTab turns off CTRL, Tab, Left Win, Right Win and App key during the password input, so you are stuck in the password window :)
;-------------------------------------------------------------------------------------------------------------------------
Func _noTab($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)

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

If $vkCode = 0x11 or $vkCode = 0x09 or $vkCode = 0x5B or $vkCode = 0x5C or $vkCode = 0x5D Then Return 1

_WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)
EndFunc


; Func _unlockAll unlocks all (?! really:))
;----------------------------------------
Func _unlockAll()
DllCallbackFree($pStub_KeyProc)
DllCallbackFree($pStub_MouseProc)
_WinAPI_UnhookWindowsHookEx($hHookKeyboard)
_WinAPI_UnhookWindowsHookEx($hHookMouse)
EndFunc

Edited by elemirac, 06 July 2009 - 04:01 PM.


#16 elemirac

elemirac

    Seeker

  • New Members
  • 3 posts

Posted 08 July 2009 - 01:38 PM

Sorry, I had a small bug in the last one. Fixed it here by adding Func _preUnlock(). Without this function I had a problem if someone strikes PAUSE key in PC Unlocked state, or if the same key is pressed while the password window is already shown.
Here is the corrected code:

AutoIt         
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=lockPC.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPI.au3> #include <Timers.au3> #include <Date.au3> Opt("TrayMenuMode", 1) Opt("WinTitleMatchMode", 2) HotKeySet("{PAUSE}", "_preUnlock") ; Values ;------- $idleTimeValue = 10000 ; Idle time to wait until lock $validPass = "pass" ; This password unlocks all, but program still counts idle time and will lock all again if there's no user input $ultimatePass = "secret" ; With this password all is unlocked and program exits $iniFile = "C:\lockPC.log" ; Location and name of log file ;$password = "" ; Declaration of input box variable (must be like this) IniWrite($iniFile, @ComputerName & " - Log", _Now(), "Program started") ; This is the initial idle time check, after this IDLE time PC is locked ;----------------------------------------------------------------------- while 1     if _Timer_GetIdleTime()<$idleTimeValue Then         ContinueLoop     Else         ExitLoop     EndIf WEnd Global $pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr") Global $pStub_MouseProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr") Global $hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0) Global $hHookMouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($pStub_MouseProc), _WinAPI_GetModuleHandle(0), 0) SplashTextOn ( "Lock", "Keyboard and mouse locked!" & @LF & @LF & "Press PAUSE key to unlock",300,100,20,-1,1,"",14,200) for $anim = 0 to 360     WinSetTrans("Lock","",$anim/2) Next IniWrite($iniFile, @ComputerName & " - Log", _Now(), "PC Locked") While 1     Sleep(100) WEnd ; Func _preUnlock is making sure that _UnBlock should be called, without this the script has a bug ;------------------------------------------------------------------------------------------------- Func _preUnlock()     If WinExists("Lock") Then         call("_UnBlock")     Else         Beep(500, 100)     EndIf EndFunc ; Func _UnBlock runs password check and unlocks only keys needed for password input ;---------------------------------------------------------------------------------- Func _UnBlock()         for $anim = 360 to 0 step -1       WinSetTrans("Lock","",$anim/2)     Next     SplashOff()         DllCallbackFree($pStub_KeyProc)     _WinAPI_UnhookWindowsHookEx($hHookKeyboard)         $pStub_KeyProc = DllCallbackRegister("_noTab", "int", "int;ptr;ptr")     $hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0)         $password = InputBox("UnBlock", "Enter the password", "", "*",-1,130)         ; Password check ;----------------     if $password = $validPass Then         call("_unlockAll")         IniWrite($iniFile, @ComputerName & " - Log", _Now(), "PC Unlocked")         while 1                         ; Again idle time check, after this IDLE time PC is locked             ;----------------------------------------------------------             if _Timer_GetIdleTime()<$idleTimeValue Then                 ContinueLoop             Else                 call("_unlockAll")                 call("_block")                                 IniWrite($iniFile, @ComputerName & " - Log", _Now(), "PC Locked")                 SplashTextOn ( "Lock", "Keyboard and mouse locked!" & @LF & @LF & "Press PAUSE key to unlock",300,100,20,-1,1,"",14,200)                 for $anim = 0 to 360                     WinSetTrans("Lock","",$anim/2)                 Next                 ExitLoop             EndIf         WEnd         ;Exit     ElseIf $password = $ultimatePass Then         call("_unlockAll")                 IniWrite($iniFile, @ComputerName & " - Log", _Now(), "Secret Password - Program end")         Exit     else         ;WinClose("UnBlock")         call("_unlockAll")         call("_block")                 IniWrite($iniFile, @ComputerName & " - Log", _Now(), "Unlock Attempt - Wrong password")         SplashTextOn ( "Lock", "Keyboard and mouse locked!" & @LF & @LF & "Press PAUSE key to unlock",300,100,20,-1,1,"",14,200)         for $anim = 0 to 360             WinSetTrans("Lock","",$anim/2)         Next     EndIf EndFunc ; Func _KeyProc determines which keys are locked - $vkCode <> values are keys that are UNLOCKED (Pause key [0x13] and ENTER [0x0D]) ;---------------------------------------------------------------------------------------------------------------------------------- Func _KeyProc($nCode, $wParam, $lParam)     If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)         Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)     Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")         If $vkCode <> 0x13 and $vkCode <> 0x0D Then Return 1         _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam) EndFunc Func _Mouse_Handler($nCode, $wParam, $lParam)     If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookMouse, $nCode, $wParam, $lParam)         Return 1 EndFunc ; Func _block is locking everything ;---------------------------------- Func _block()     $pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")     $pStub_MouseProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr")     $hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0)     $hHookMouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($pStub_MouseProc), _WinAPI_GetModuleHandle(0), 0) EndFunc ; Func _noTab turns off CTRL, Tab, Left Win, Right Win and App key during the password input ;------------------------------------------------------------------------------------------- Func _noTab($nCode, $wParam, $lParam)     If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)         Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)     Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")         If $vkCode = 0x11 or $vkCode = 0x09 or $vkCode = 0x5B or $vkCode = 0x5C or $vkCode = 0x5D Then Return 1     _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam) EndFunc ; Func _unlockAll unlocks all (?! really) ;---------------------------------------- Func _unlockAll()     DllCallbackFree($pStub_KeyProc)     DllCallbackFree($pStub_MouseProc)     _WinAPI_UnhookWindowsHookEx($hHookKeyboard)     _WinAPI_UnhookWindowsHookEx($hHookMouse) EndFunc

Edited by elemirac, 08 July 2009 - 01:44 PM.


#17 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 24 September 2009 - 09:33 PM

Small update!

History version:

[v1.3 - 24.09.2009, 23:00]
+ Added _BlockInputEx Example (Pass Lock)
* Fixed few examples.
* Fixed spell mistakes in the UDF.

[v1.2 - 16.01.2009, 21:00]
+ Added key strings support.
------Now users can set simple hotkey strings for Exclude/Include parameters + Group chars, i.e: "[Group]|{UP}|{DOWN}"
-------(See UDF documentation)
+ Added mouse events blocking support to the $sExclude/$sInclude parameters.
+ Added example for mouse events blocking.


Edited by MrCreatoR, 24 September 2009 - 09:50 PM.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#18 epicfail

epicfail

    Prodigy

  • Active Members
  • PipPipPip
  • 182 posts

Posted 01 October 2009 - 11:11 AM

this is great ty i love it.

#19 Emolas

Emolas

    Seeker

  • Active Members
  • 16 posts

Posted 06 October 2009 - 07:09 PM

Awesome script and very useful. Is there any way to get it to block USER mouse input but still enable script input via mousemove()?

#20 PieMan

PieMan

    Seeker

  • Active Members
  • 37 posts

Posted 06 October 2009 - 11:08 PM

Very nice! This will really help me out in one of my programs :)

Just one thing though... Is it possible to block all input except for a certain window? I see here you can block input on just a specified window but what about the other way round?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users