Jump to content

Recommended Posts

This function can be use to block all inputs coming from mouse and keyboard, without having an UAC warning displayed.

Version 2021-02-06

* Allows blocking either Mouse or Keyboard independently

* Removed @error if already disable / enable

* Checks for rightful parameters

Basic Example :

#include "BlockInputEX.au3"

Opt("MustDeclareVars", 1)

_BlockInput($BI_DISABLE)              ; block input
ConsoleWrite("Block all inputs" & @LF)
_BlockInput($BI_DISABLE)              ; useless since already disable
Sleep(10000)
_BlockInput($BI_ENABLE)               ; enable input
ConsoleWrite("Enable all inputs" & @LF)
_BlockInput($BI_ENABLE)               ; useless set since already enable
Sleep(5000)

_BlockInput($BI_DISABLE, $BI_MOUSE)   ; block input mouse only
ConsoleWrite("Block mouse only" & @LF)
Sleep(10000)
_BlockInput($BI_DISABLE, $BI_KEYBOARD); block input keyboard also
ConsoleWrite("Block keyboard" & @LF)
Sleep(10000)
_BlockInput($BI_ENABLE, Default)      ; enable all input
ConsoleWrite("Reenable all inputs" & @LF)

How to release a Block Example :

#include <Constants.au3>
#include <Misc.au3>
#include "BlockInputEX.au3"

Opt("MustDeclareVars", 1)

_BlockInput($BI_DISABLE)

Local $hTimer = TimerInit()
While TimerDiff($hTimer) < 15000
  If _IsPressed("10") And _IsPressed("11") And _IsPressed("12") Then ; pressing Ctrl-Shift-Alt release the block immediately
    Exit _BlockInput($BI_ENABLE)
  EndIf
WEnd

_BlockInput($BI_ENABLE)

 

BlockInputEX.au3

Edited by Nine
Link to post
Share on other sites
  • 1 month later...

Great work on this Nine!

 

Just because I'm super lazy and I just needed this to resolve a ControlSend issue, I created this from your code.

It's used just like you would ControlSend, but it blocks and unblocks keyboard and mouse during the process.

 

; #FUNCTION# ====================================================================================================================
; Name...........: _ControlSendSecure
; Description ...: Block all mouse and keyboard inputs, Sends Text to the control, then Unblocks all mouse and keyboard inputs
; Syntax.........: _ControlSendSecure()
; Parameters ....:
; Return values .: Success - Returns 1
;                  Failure - Returns 0
; Author ........: BigDaddyO, based off Nines _BlockInputEx
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _ControlSendSecure($s_Title, $s_Text, $s_ControlID, $s_Value, $bFlag = 0)
    $g_hStub_KeyProc = DllCallbackRegister("_BlockInput_MouseKeyProc", "long", "int;wparam;lparam")
    $g_hStub_MouseProc = DllCallbackRegister("_BlockInput_MouseKeyProc", "long", "int;wparam;lparam")
    Local $hMod = _WinAPI_GetModuleHandle(0)
    $g_hHook1 = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)
    $g_hHook2 = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_MouseProc), $hMod)

    $iRet = ControlSend($s_Title, $s_Text, $s_ControlID, $s_Value, $bFlag)

    _WinAPI_UnhookWindowsHookEx($g_hHook1)
    _WinAPI_UnhookWindowsHookEx($g_hHook2)
    DllCallbackFree($g_hStub_KeyProc)
    DllCallbackFree($g_hStub_MouseProc)
    
    Return $iRet
EndFunc

 

Edited by BigDaddyO
Link to post
Share on other sites
  • 3 weeks later...

Added to the wiki :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2021-07-20 - Version 1.0.0.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Added example how to release a block all input without restarting the computer (in case a problem occurs while the computer is blocked).

Link to post
Share on other sites
On 7/30/2019 at 1:32 PM, Nine said:

This function can be use to block all inputs coming from mouse and keyboard, without having an UAC warning displayed.

That was what I was looking for. Thanks a lot!

On 10/4/2019 at 2:01 PM, Nine said:

I'll thing about a new name...

How about ;)
BlockInputEx9
BlockInputExBy9

...

Link to post
Share on other sites
  • 2 weeks later...

Hello everyone, everything works as it says above.
Is it possible that it will work that way?
User input is blocked and AutoIt can simulate mouse and keyboard.

Link to post
Share on other sites
Link to post
Share on other sites
Posted (edited)

Too bad ☹️

The standard BlockInput function also works for me.

But the function needs #RequireAdmin and that is exactly what causes me little problems.

Edited by Norm73
Link to post
Share on other sites
Posted (edited)
28 minutes ago, Norm73 said:

As soon as I use #RequireAdmin, I no longer have access to the external drive.

Nine’s solution _BlockInput(), unlike the standard BlockInput(), does not require #RequireAdmin.

However, during the block, Send() and MouseDown() do not work.

Instead, you need to use ControlSend() and ControlClick().  

These functions take at least a window handle as a parameter, and direct the keystroke/click to that window.

I haven’t had a problem using and them, even with third party windows, and they’re far more predictable, especially when you are worried about simultaneous user interaction, which I’m guessing you are.

Why don’t you try it out and if it doesn’t work correctly, post the code.

Edited by JockoDundee

Code hard, but don’t hard code...

Link to post
Share on other sites

Hello JockoDundee

I know that it is all best to do this via ControlSend.

Suffer my program where I do the emulation is not that simple and the handles are constantly changing.

I have taken note of this and am trying to do all of this via ControlSend.

Thank you very much!

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...