Jump to content

how to do this programming?


jing
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...