Sign in to follow this  
Followers 0
jing

how to do this programming?

4 posts in this topic

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

Share this post


Link to post
Share on other sites



nobody can give me a word?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

GetLastInputInfo API function can't do that, so maybe some workaround :lmao:

For example try to test Mouse position by MouseGetPos() - if changes mouse position then ignore GetLastInputInfo.

Edited by Zedna

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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
Sign in to follow this  
Followers 0