mylearings Posted June 30, 2023 Posted June 30, 2023 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 able to block keyboard input using this script not able to block mouse interaction using laptop mousepad 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 Melba23 Posted June 30, 2023 Moderators Posted June 30, 2023 Moved to the appropriate forum. Moderation Team 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mylearings Posted July 5, 2023 Author Posted July 5, 2023 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 able to block keyboard input using this script not able to block mouse interaction using laptop mousepad 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)
Developers Jos Posted July 5, 2023 Developers Posted July 5, 2023 Why open another thread on the exact same topic? Please don't! SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Andreik Posted July 5, 2023 Posted July 5, 2023 (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 July 5, 2023 by Andreik
mylearings Posted July 5, 2023 Author Posted July 5, 2023 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
Andreik Posted July 5, 2023 Posted July 5, 2023 Did you run at least the script? Is your mouse moving?
mylearings Posted July 5, 2023 Author Posted July 5, 2023 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
Andreik Posted July 5, 2023 Posted July 5, 2023 You must be joking. How do you think you block keyboard input but still sending keys using Send() function?
mylearings Posted July 5, 2023 Author Posted July 5, 2023 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
Andreik Posted July 5, 2023 Posted July 5, 2023 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
mylearings Posted July 5, 2023 Author Posted July 5, 2023 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?
Andreik Posted July 5, 2023 Posted July 5, 2023 (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: expandcollapse popup#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 July 5, 2023 by Andreik
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now