Jump to content

Recommended Posts

Posted

I want to write a program that can react to the user's action including mouse click, mouse release, and key pressed.

The following code is an example that can achieve my goal(Thanks, Larry). However, it reacts to mouse movement as well, which I don't want.

Anybody can give me a hint how to achieve my goal perfectly?

HotKeySet("{Esc}", "_Terminate")

Dim $last_active = 0

Dim $timer = TimerInit()

While (1)

$not_idle = _CheckIdle($last_active)

If $not_idle <> 0 Then $timer = TimerInit()

ToolTip(Int(TimerDiff($timer)/1000))

Sleep(200)

WEnd

Func _CheckIdle(ByRef $last_active, $start = 0)

$struct = DllStructCreate("uint;dword");

DllStructSetData($struct, 1, DllStructGetSize($struct));

If $start Then

DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))

$last_active = DllStructGetData($struct, 2)

Return $last_active

Else

DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))

If $last_active <> DllStructGetData($struct, 2) Then

Local $save = $last_active

$last_active = DllStructGetData($struct, 2)

Return $last_active - $save

EndIf

EndIf

EndFunc ;==>_CheckIdle

Func _Terminate()

Exit

EndFunc ;==>_Terminate

Posted

that is not a straight forward way to do that.

There must be some function or functions can directly detect the key press or mouse click.

Anybody knows that?

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
×
×
  • Create New...