LucianoCruz Posted June 29, 2023 Posted June 29, 2023 Hello, does anyone have a script that checks if the keyboard is idle for 5 minutes, if it is then it sends ESC. I want to use it to implement a code that I have in my arcade. Grateful
Andreik Posted June 29, 2023 Posted June 29, 2023 (edited) Welcome to the forum! Maybe you didn't noticed but you posted in the wrong section of the forum and this is a forum where people get help after they tried something and didn't work. Since it's a simple script I will give you an example but please keep these things in mind when you ask for more help. #include <WinAPIConstants.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Global $hProc, $hHook, $nTimer, $bExit = False $hProc = DllCallbackRegister('KeyboardProc', 'long', 'int;wparam;lparam') $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0)) $nTimer = TimerInit() Do If Int(TimerDiff($nTimer) / 1000) >= 300 Then Send('{ESC}') ; 5 Minutes Sleep(10) Until $bExit _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hProc) Func KeyboardProc($nCode, $wParam, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) If $wParam = $WM_KEYDOWN Then Local $tKBDLLHOOKSTRUCT = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) ; Press HOME key to exit If DllStructGetData($tKBDLLHOOKSTRUCT, "vkCode") = 0x24 Then $bExit = True ConsoleWrite('Keyboard was idle for ' & Int(TimerDiff($nTimer) / 1000) & ' seconds.' & @CRLF) $nTimer = TimerInit() EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc Edited June 29, 2023 by Andreik
Moderators Melba23 Posted June 29, 2023 Moderators Posted June 29, 2023 LucianoCruz, Take a look at the _WinAPI_GetIdleTime and _Timer_GetIdleTime functions - they might be a bit easier to use than subclassing! M23 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
Andreik Posted June 29, 2023 Posted June 29, 2023 As I understand he is interested to get just the keyboard idle time. If he's looking also for mouse idle time _WinAPI_GetIdleTime() it's definitely better.
LucianoCruz Posted July 30, 2023 Author Posted July 30, 2023 Hello, guys, I looked for it but I didn't find it, I need a script that detects keyboard inactivity, if the keyboard stays for 1 minute without any user action, then it sends ESC and is paused, if there is any user activity then it goes back to monitoring again the activity
Andreik Posted July 30, 2023 Posted July 30, 2023 Why would you post the same question twice? You got some answers there. If it doesn't fit your needs you can ask more questions in the same thread.
Developers Jos Posted July 31, 2023 Developers Posted July 31, 2023 Topics merged: Please stick to one for here on. 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.
LucianoCruz Posted August 2, 2023 Author Posted August 2, 2023 Thanks! I got confused, and ended up posting 2 times, I'm going to test the Script, and sorry for my carelessness, it won't be repeated
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