Jump to content

Recommended Posts

Posted

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

Posted (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 by Andreik
  • Moderators
Posted

LucianoCruz,

Take a look at the _WinAPI_GetIdleTime and _Timer_GetIdleTime functions - they might be a bit easier to use than subclassing!

M23

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

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.

  • 1 month later...
Posted
 
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

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