Jump to content

Unable to block users from interaction using mouse with BlockInput() option from laptop mousepad(Inspiron 14 5410 2 in 1) - (Moved)


Recommended Posts

Posted

Hello Team,

I am using the below script in which I want to restrict users from interacting through mouse & keyboard till automation gets complete

but this script is not working on my Inspiron 14 5410 2 in 1 laptop & below is the observation

  1. able to block keyboard input using this script 
  2. not able to block mouse interaction using laptop mousepad
  3. when i am connecting the external mouse to the laptop the script is blocking external mouse interaction through the laptop mousepad still working

#RequireAdmin
#include <AutoItConstants.au3>

BlockInput($BI_DISABLE)

Run("C:\Program Files\Google\Chrome\Application\chrome.exe https://www.facebook.com/")
Sleep (15000 )

Send("loginid")
Send("{TAB}")
Send("password")
Send("{ENTER}")
BlockInput($BI_ENABLE) 

  • Moderators
Posted

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Hello Team,

I am using the below script in which I want to restrict users from interacting through mouse & keyboard till automation gets complete

but this script is not working on my Inspiron 14 5410 2 in 1 laptop & below is the observation

  1. able to block keyboard input using this script 
  2. not able to block mouse interaction using laptop mousepad
  3. when i am connecting the external mouse to the laptop the script is blocking external mouse interaction through the laptop mousepad still working

#RequireAdmin
#include <AutoItConstants.au3>

BlockInput($BI_DISABLE)

Run("C:\Program Files\Google\Chrome\Application\chrome.exe https://www.facebook.com/")
Sleep (15000 )

Send("loginid")
Send("{TAB}")
Send("password")
Send("{ENTER}")
BlockInput($BI_ENABLE)

Posted (edited)

Maybe a low level keyboard hook like in this example:

#include <WinAPISys.au3>
#include <WinAPIConstants.au3>

Global $hProc = DllCallbackRegister('MouseProcedure', 'long', 'int;wparam;lparam')
Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0))

BlockInput(1)
; Do you stuff here
Sleep(10000)
BlockInput(0)

_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hProc)

Func MouseProcedure($nCode, $wParam, $lParam)
    If $wParam = 0x0200 Then Return True ; WM_MOUSEMOVE
    _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

 

Edited by Andreik
Posted
10 minutes ago, Andreik said:

Maybe a low level keyboard hook like in this example:

#include <WinAPISys.au3>
#include <WinAPIConstants.au3>

Global $hProc = DllCallbackRegister('MouseProcedure', 'long', 'int;wparam;lparam')
Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0))

BlockInput(1)
; Do you stuff here
Sleep(10000)
BlockInput(0)

DllCallbackFree($hProc)

Func MouseProcedure($nCode, $wParam, $lParam)
    If $wParam = 0x0200 Then Return True ; WM_MOUSEMOVE
    _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

 

BlockInput(0) method not working only working old laptops
able to block keyboard, mouse still working

 

Posted
34 minutes ago, Andreik said:

Did you run at least the script? Is your mouse moving?

yes

able to block the mouse keyboard input was working so added required admin, now automation is not working
made below changes in your code
 

#include <WinAPISys.au3>
#include <WinAPIConstants.au3>
#include <AutoItConstants.au3>

#RequireAdmin

Global $hProc = DllCallbackRegister('MouseProcedure', 'long', 'int;wparam;lparam')
Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0))

BlockInput(1)
; Do you stuff here

Run("C:\Program Files\Google\Chrome\Application\chrome.exe https://www.facebook.com/")
AutoItSetOption('MouseCoordMode', 0)
Sleep(2000)

WinWaitActive("Facebook – log in or sign up - Google Chrome")
Sleep(2000)

MouseClick('primary', 915, 260, 1, 0)
Send("username")
MouseClick('primary', 950, 325, 1, 0)
Send("password")
Sleep(1000)
Send("{TAB}")
Send("{ENTER}")

BlockInput(1)

DllCallbackFree($hProc)

Func MouseProcedure($nCode, $wParam, $lParam)
    If $wParam = 0x0200 Then Return True ; WM_MOUSEMOVE
    _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

 

Posted

Actually, the issue in my previous code is I was using mouse co-ordinate to click on the fields & due to mouse blocking it was not working
with send function able to send the inputs to input field using TAB


my main motive behind this script is to restrict the user input & let the autoIT manage every event till the automation process gets completed

with this code now my mouse is not moving but able to click in between the automation due to which inputs are getting forwarded to different fields as i am using TAB as mousecoords method not working
 

#include <WinAPISys.au3>
#include <WinAPIConstants.au3>
#include <AutoItConstants.au3>

#RequireAdmin

Global $hProc = DllCallbackRegister('MouseProcedure', 'long', 'int;wparam;lparam')
Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0))

BlockInput(1)
; Do you stuff here

Run("C:\Program Files\Google\Chrome\Application\chrome.exe https://www.facebook.com/")
;AutoItSetOption('MouseCoordMode', 0)
;Sleep(2000)
WinWaitActive("Facebook – log in or sign up - Google Chrome")
Sleep(1000)

;MouseClick('primary', 915, 260, 1, 0)
Send("{TAB}")
Send("username")
Send("{TAB}")
;MouseClick('primary', 950, 325, 1, 0)
Send("password")
Sleep(1000)
;Send("{TAB}")
Send("{ENTER}")
Sleep(1000)

BlockInput(1)

DllCallbackFree($hProc)

Func MouseProcedure($nCode, $wParam, $lParam)
    If $wParam = 0x0200 Then Return True ; WM_MOUSEMOVE
    _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

is there any way to achieve this

Posted
25 minutes ago, Andreik said:

You can temporary unblock input. Something like this:

#RequireAdmin

BlockInput(1)
Sleep(3000)
UnblockAndSend('Yayyy')
Sleep(3000)
BlockInput(0)

Func UnblockAndSend($sText)
    BlockInput(0)
    Send('Yayyy')
    BlockInput(1)
EndFunc

 

Can we implement the same for mouse
like release the mouse blocking before using mousecoords function & enable again after putting mouse on that field using coordinated?

Posted (edited)

It's even easier:

#include <WinAPISys.au3>
#include <WinAPIConstants.au3>

Global $TemporaryAllow = False
Global $hProc = DllCallbackRegister('MouseProcedure', 'long', 'int;wparam;lparam')
Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0))

Sleep(3000)
$TemporaryAllow = True
MouseMove(Random(1, @DesktopWidth, 1), Random(1, @DesktopHeight, 1))
$TemporaryAllow = False
Sleep(3000)

_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hProc)

Func MouseProcedure($nCode, $wParam, $lParam)
    If Not $TemporaryAllow And $wParam = 0x0200 Then Return True ; WM_MOUSEMOVE
    _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

You can create some specialized functions like in this example:

#include <WinAPISys.au3>
#include <WinAPIConstants.au3>

; By default mouse and keyboard are enabled
Global $MouseEnabled = True, $KeyboardEnabled = True

Global $hModule = _WinAPI_GetModuleHandle(0)
Global $hMouseProc = DllCallbackRegister('MouseProcedure', 'long', 'int;wparam;lparam')
Global $hKeyboardProc = DllCallbackRegister('KeyboardProcedure', 'long', 'int;wparam;lparam')
Global $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), $hModule)
Global $hKeyboardHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hKeyboardProc), $hModule)

; Disable mouse
$MouseEnabled = False

; Disable keyboard
$KeyboardEnabled = False

Sleep(3000)
SafeMouseMove(100, 100)

Sleep(3000)
SafeSend('Yayyyy')

Sleep(3000)

_WinAPI_UnhookWindowsHookEx($hMouseHook)
_WinAPI_UnhookWindowsHookEx($hKeyboardHook)
DllCallbackFree($hMouseProc)
DllCallbackFree($hKeyboardProc)

Func MouseProcedure($nCode, $wParam, $lParam)
    If Not $MouseEnabled And ($wParam = 0x0200 Or $wParam = 0x0201) Then Return True ; WM_MOUSEMOVE || WM_LBUTTONDOWN
    _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)
EndFunc

Func KeyboardProcedure($nCode, $wParam, $lParam)
    If Not $KeyboardEnabled And ($wParam = 0x0100 Or $wParam = 0x0104) Then Return True ; WM_KEYDOWN || WM_SYSKEYDOWN
    _WinAPI_CallNextHookEx($hKeyboardHook, $nCode, $wParam, $lParam)
EndFunc

Func SafeSend($sString)
    $KeyboardEnabled = True
    Send($sString)
    $KeyboardEnabled = False
EndFunc

Func SafeMouseMove($iX, $iY)
    $MouseEnabled = True
    MouseMove($iX, $iY)
    $MouseEnabled = False
EndFunc

Func SafeMouseClick($sButton, $iX, $iY, $iClicks)
    $MouseEnabled = True
    MouseClick($sButton, $iX, $iY, $iClicks)
    $MouseEnabled = False
EndFunc

 

Edited by Andreik

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...