Sign in to follow this  
Followers 0
MrCreatoR

BlockInput not work propperly?

16 posts in this topic

Why when i using BlockInput(1), not just Ctrl+Alt+Del is able to turn off this func, also when i press “Power” key, or “Sleep” key, the BlockInput is disabled and the computer go to sleep ?

Maby there is a way to block this hotkeys? or better, how to use BlockInput that only the Ctrl+Alt+Del will disable the block? (like BlockInput(0) )

And i have another question - It is possible to check, if the BlockInput is enabled? i have tried like this:

BlockInput(1)
$Ret = _IsBlocked()
MsgBox(0, "", $Ret, 5)
BlockInput(0)

Func _IsBlocked()
    Dim $Return = 1
    HotKeySet("{ALT}", "AltTest")
    Send("{ALT}")
    HotKeySet("{ALT}")
    Return $Return
EndFunc


Func AltTest()
    Global $Return = 0
EndFunc

But always returned 1. I dont understand, while BlockInput is enabled, the Alt key can not be sent, therefore, if i send Alt key while the blockinput is Disabled, it should execute the func that set $Return to 0 ( AltTest() ), but it not happened, why?


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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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 UDF
 
AutoIt_Icon_small.pngExamples: 
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 Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I just used BlockInput and it worked fine (it was for testing in my script).

Perhaps the usage of ALT as a hotkey itself, since ALT is a "shifting" key instead of an actual value is an issue?

Or that you are doing a Dim in one function and a Global in another for the same value. Overwriting the values... could be defaulting to one all the time.

Edited by gnosis3d

Share this post


Link to post
Share on other sites

From the Help File:

If BlockInput is enabled, the Alt keypress cannot be sent!

It is not correct, see this example:

BlockInput(1)
$Ret = _IsBlocked()
MsgBox(0, "", $Ret, 3)
BlockInput(0)

Func _IsBlocked()
    Global $Return = 1
    HotKeySet("!o", "AltTest")
    Send("!{o}")
    Return $Return
EndFunc

Func AltTest()
    Global $Return = 0
EndFunc

Returned 0, couse the function AltTest is executed, how it can be possible if the alt key can not be sent?

Somebody - how can i check if the BlockInput is enabled or disabled? - and also, how to set this function, that just Cll+Alt+Del will stop (disable) this function?

Thanx!


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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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 UDF
 
AutoIt_Icon_small.pngExamples: 
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 Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Returned 0, couse the function AltTest is executed, how it can be possible if the alt key can not be sent?

Look further down the page with the remarks of BlockInput().

If you are using Windows XP then you should be aware that a hotfix released inbetween SP1 and SP2 limited Blockinput so that the ALT key could NOT be sent. This is fixed in XP SP2.

So I guess your not using Windows XP SP1 with the hotfix that caused the ALT key change of behaviour?

As for the power or sleep keys, a standard 102 button keyboard does not have them so it is extra buttons added by the manufacturer of the device.

Share this post


Link to post
Share on other sites

Look further down the page with the remarks of BlockInput().

Oops :"> sorry, i didn't see this, and yes, i have an SP2 on my Windows.

As for the power or sleep keys, a standard 102 button keyboard does not have them so it is extra buttons added by the manufacturer of the device.

Ok, thanx. But, in the case that i have more than 102 buttons in my keyboard (moust keyboards of today have more then 102 buttons :) ), how can i disable them using AutoIt? (while or before execute the func BlockInput).

Why i need this? well, i have write a very big script, that help me to clean my mouse and keyboard :whistle: (using BlockInput), but by accident when i clean the keyboard, i press the “Power” button, and the computer was shutdown.

And i just like to know how to block all inputs except the Ctrl+Alt+Del - It is possible?


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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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 UDF
 
AutoIt_Icon_small.pngExamples: 
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 Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Any one?

I just need a way to block all keys except Ctrl Alt Del :whistle:


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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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 UDF
 
AutoIt_Icon_small.pngExamples: 
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 Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Any one?

I just need a way to block all keys except Ctrl Alt Del :whistle:

I'm looking for a similair thing, I don't want Ctrl + Alt + Del to do it. But I want a different key to unblock it. The problem is the hotkeys won't work because they keyboard is blocked.

[center]My BlogOldSock Programs (AutoIT Apps)A Message to Hackers! (NOT SKIDDIES!)OldSock Programs is my little "company."[/center]

Share this post


Link to post
Share on other sites

I believe the easiest way to do this is to search nonags.com or some other download

site that has software that is written in another language that talks more in

machine language. Since the language is a little more advanced than AutoIt,

then it should do the trick. Or, you could just shut the computer down or

unplug the devices during the cleaning process.


"...Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like.My crime is that of outsmarting you, something that you will never forgive me for." --The Mentor"Mess with the best, die like the rest!!" -Hackers"This above all to thine own self be true." -William Shakespeare"Corruption is only as corrupted as the individual makes it out to be." -Mozart_ONLINECheck out this free 1 GB FTP website at DriveHQ.com. You can control the users and even publish a website for free!![s]Your-Start.com - A online website that you can customize to hold all you links, news information, and other website info.[/s]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Almoust year after :P , maybe someone have an idea how to block extra buttons on the keyboard? ;)

P.S

I need it for my KeyBoard & Mouse Cleaner project :).

Edited by MsCreatoR

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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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 UDF
 
AutoIt_Icon_small.pngExamples: 
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 Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

There you go...

Thanks, but it not lock out the Power/Sleep keys :P

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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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 UDF
 
AutoIt_Icon_small.pngExamples: 
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 Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thanks, but it not lock out the Power/Sleep keys :P

Well what exactly happens at boot time?

If you boot without the keyboard plugged in, and then plug it in later, it does not work.

Try to disrupt the Device manager somehow to mimic that effect.

Edited by Oldschool

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Thanks for the idea, i think if there will be a way to unplug/plug the keyboard device (programly), then my problem is solved...

Maybe someone know how to do this? :P

Edited by MsCreatoR

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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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 UDF
 
AutoIt_Icon_small.pngExamples: 
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 Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Ok, here is a solution (by amel27 :P) ...

;Example for using with DllCallBack.au3 library (for AutoIt v3.8.2.1 and lower)

#include <DllCallBack.au3>
Global $hWinHook

$CallBackProc = TogglePlugKeyBoard()
MsgBox(4096, "", "KeyBoard is disabled, press OK to enable it :).")

TogglePlugKeyBoard($CallBackProc)
MsgBox(4096, "", "KeyBoard is enabled!")

Exit

Func TogglePlugKeyBoard($hCallProc=0)
    If IsArray($hWinHook) Then
        DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hWinHook[0])
        _DllCallBack_Free($hCallProc)
        Return 0
    EndIf
    
    Local Const $WH_KEYBOARD_LL = 13
    Local $hKeyProc = _DllCallBack("_KeyProc", "int;ptr;ptr")
    Local $hMod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
    $hWinHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", _
        "int", $WH_KEYBOARD_LL, _
        "ptr", $hKeyProc, _
        "hwnd", $hMod[0], _
        "dword", 0)
    Return $hKeyProc
EndFunc

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Local $iRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hWinHook[0], _
            "int", $nCode, _
            "ptr", $wParam, _
            "ptr", $lParam)
        Return $iRet[0]
    EndIf
    Return 1
EndFunc


;=============================================
;Example only for AutoIt v3.2.10.0 and higher:

Global $hWinHook

$CallBackProc = TogglePlugKeyBoard()
MsgBox(4096, "", "KeyBoard is disabled, press OK to enable it :).")

TogglePlugKeyBoard($CallBackProc)
MsgBox(4096, "", "KeyBoard is enabled!")

Exit

Func TogglePlugKeyBoard($hCallProc=0)
    If IsArray($hWinHook) Then
        DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hWinHook[0])
        DllCallbackFree($hCallProc)
        Return 0
    EndIf
    
    Local Const $WH_KEYBOARD_LL = 13
    Local $hKeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
    Local $hMod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
    $hWinHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", _
        "int", $WH_KEYBOARD_LL, _
        "ptr", DllCallbackGetPtr($hKeyProc), _
        "hwnd", $hMod[0], _
        "dword", 0)
    Return $hKeyProc
EndFunc

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Local $iRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hWinHook[0], _
            "int", $nCode, _
            "ptr", $wParam, _
            "ptr", $lParam)
        Return $iRet[0]
    EndIf
    Return 1
EndFunc

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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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 UDF
 
AutoIt_Icon_small.pngExamples: 
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 Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Ok, here is a solution (by amel27 ;)) ...

;Example for using with DllCallBack.au3 library (for AutoIt v3.8.2.1 and lower)

#include <DllCallBack.au3>
Global $hWinHook

$CallBackProc = TogglePlugKeyBoard()
MsgBox(4096, "", "KeyBoard is disabled, press OK to enable it :).")

TogglePlugKeyBoard($CallBackProc)
MsgBox(4096, "", "KeyBoard is enabled!")

Exit

Func TogglePlugKeyBoard($hCallProc=0)
    If IsArray($hWinHook) Then
        DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hWinHook[0])
        _DllCallBack_Free($hCallProc)
        Return 0
    EndIf
    
    Local Const $WH_KEYBOARD_LL = 13
    Local $hKeyProc = _DllCallBack("_KeyProc", "int;ptr;ptr")
    Local $hMod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
    $hWinHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", _
        "int", $WH_KEYBOARD_LL, _
        "ptr", $hKeyProc, _
        "hwnd", $hMod[0], _
        "dword", 0)
    Return $hKeyProc
EndFunc

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Local $iRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hWinHook[0], _
            "int", $nCode, _
            "ptr", $wParam, _
            "ptr", $lParam)
        Return $iRet[0]
    EndIf
    Return 1
EndFunc


;=============================================
;Example only for AutoIt v3.2.10.0 and higher:

Global $hWinHook

$CallBackProc = TogglePlugKeyBoard()
MsgBox(4096, "", "KeyBoard is disabled, press OK to enable it :).")

TogglePlugKeyBoard($CallBackProc)
MsgBox(4096, "", "KeyBoard is enabled!")

Exit

Func TogglePlugKeyBoard($hCallProc=0)
    If IsArray($hWinHook) Then
        DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hWinHook[0])
        DllCallbackFree($hCallProc)
        Return 0
    EndIf
    
    Local Const $WH_KEYBOARD_LL = 13
    Local $hKeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
    Local $hMod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
    $hWinHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", _
        "int", $WH_KEYBOARD_LL, _
        "ptr", DllCallbackGetPtr($hKeyProc), _
        "hwnd", $hMod[0], _
        "dword", 0)
    Return $hKeyProc
EndFunc

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Local $iRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hWinHook[0], _
            "int", $nCode, _
            "ptr", $wParam, _
            "ptr", $lParam)
        Return $iRet[0]
    EndIf
    Return 1
EndFunc
Edited by Generator

Share this post


Link to post
Share on other sites

This is really useful :P

Niiiiiiiceeeeeeeeeeeee

Share this post


Link to post
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
Sign in to follow this  
Followers 0