MouseSpotter

UDF Input Event Capture - Mouse & Keyboard

18 posts in this topic

#1 ·  Posted (edited)

This module allows a program to monitor mouse events and keyboard events.

The module invokes user defined _InputEvent_* functions to process events captured.

Documentation

====================================================================================

: Requires InputEvent.dll

: Note: if you put the InputEvent.au3 into the autoit Include folder - you can use #Include <InputEvent.au3> to include the file

: Note: you MUST put the dll in the same folder as the executeable / script

====================================================================================

====================================================================================

: NOTE: only keyboard events for windows created by the parent executeable / script are captured

====================================================================================

The events monitored are:

Drag - where a mouse button is held down, moved and released

Actions monitored:

DragStart($handle)

returns ($handle)

- handle to object being dragged

DragMove

returns ($handle,$x,$y)

- handle to object being dragged

- mouse x position

- mouse y position

DargEnd($handle)

returns ($handle)

- handle to object being dragged

Focus

Actions monitored:

GotFocus($handle)

returns $handle

- handle of object that has just been given focus

LostFocus($handle)

returns ($handle)

- handle of object that has just lost focus

Key

Actions monitored:

KeyDown

returns ($handle,$keyName,$keyValue,$shift,$ctrl,$alt,$ticks)

- handle of the object that has keyboard focus

- the name of the key

- the derived value of the key (depends on shift/ctrl/alt values)

- state of shift key (down = true, up = false)

- state of ctrl key (down = true, up = false)

- state of alt key (down = true, up = false)

- the machine tick value (time) of the keydown

KeyUp

returns ($handle,$keyName,$keyValue,$shift,$ctrl,$alt,$ticks)

- handle of the object that has keyboard focus

- the name of the key

- the derived value of the key (depends on shift/ctrl/alt values)

- state of shift key (down = true, up = false)

- state of ctrl key (down = true, up = false)

- state of alt key (down = true, up = false)

- the machine tick value (time) of the keydown

Mouse

Actions monitored:

MouseClick

returns ($handle,$button,$x,$y)

- handle of the object the mouse is on

- button being used

- mouse coordinates

MouseDown

returns ($handle,$button,$x,$y,$ticks)

- handle of the object the mouse is on

- button being used

- the machine tick value (time) of the keydown

- mouse coordinates

- the machine tick value (time) of the mousedown

MouseEnter

returns ($handle)

- handle of the object the mouse has entered

MouseLeave

returns ($handle)

- handle of the object the mouse has left

MouseMove

returns ($handle,$x,$y)

- handle of the object the mouse is on

- mouse coordinates

MouseUp($handle,$button,$x,$y,$ticks)

returns:

- handle of the object the mouse is on

- button being used

- mouse coordinates

- the machine tick value (time) of the mousedown

Usage

#include <inputEvent.au3>

func _InputEvent_<action>(<returned arguments>)

your response to the event goes here

endfunc

where <action> and <returned arguments> is one of the following example functions

Example functions

Func _InputEvent_DragEnd($handle)

Func _InputEvent_DragMove($handle,$x,$y)

Func _InputEvent_DragStart($handle)

Func _InputEvent_GotFocus($handle)

Func _InputEvent_LostFocus($handle)

Func _InputEvent_KeyDown($handle,$keyname,$keyvalue,$shift,$ctrl,$alt,$ticks)

Func _InputEvent_KeyUp($handle,$keyname,$keyvalue,$shift,$ctrl,$alt,$ticks)

Func _InputEvent_MouseClick($handle,$button,$x,$y)

Func _InputEvent_MouseDown($handle,$button,$x,$y,$ticks)

Func _InputEvent_MouseEnter($handle)

Func _InputEvent_MouseLeave($handle)

Func _InputEvent_MouseMove($handle,$x,$y)

Func _InputEvent_MouseUp($handle,$button,$x,$y,$ticks)

Note

1._InputEvent_StartUp() is required to start capturing events

you can optionally capture just mouse events or key events

1. You can use only the functions you require. There is no requirement to have every _InputEvent action defined.

2. Calling _InputEvent_SetDebug(true) can help you identify if your _InputEvent function is formatted correctly by telling you if an _InputEvent<p>

InputEvent version 1.2a

InputEvent 1.2a.zip

Attachment contains:

  • InputEvent.au3
  • InputEvent.dll
  • Examples

  • example_full,au3 demonstrating all events captured
  • example_simple.au3 demonstrating mouseMove event capture
Edited by MouseSpotter
1 person likes this

Share this post


Link to post
Share on other sites



Looks nice!But I can't download the attachment.


董小姐,你微笑的时候很美,就像安河桥下,清澈的水...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

We have had a background conversation and we will let this continue for the moment.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Made InputEvent.au3 keylogger safe.

Only windows belonging to the executable will receive Key events and then only when that window has focus.

Share this post


Link to post
Share on other sites

Warning: windows taskbar appears to consume the mouseUp event when you change windows using a taskbar button.

This means that InputEvent sees a mouseDown event, never sees the mouseUp event and assumes that the next mouseMove is a Drag event.

Looking into this issue.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

New version 1.1

Fix #1

MouseLeave event sent after new object MouseMove event.

MouseLeave events now triggered in following order - MouseMove (old object) > MouseLeave (old object) > MouseEnter (new object) > MouseMove (new object)

Fix #2

Suppressed MouseMove events while dragging. drag events now: MouseDown > DragStart > DragMove > DragEnd > MouseUp

Fix #3

Prevent multiple triggers of the same event

Improvement

Added _InputEvent_ShowDebug command to show a gui where events as displayed as they occur

Improvement

Debug messages now include event arguments

Note: new version for InputEvent.dll has been included and is required by this version.

Edited by MouseSpotter

Share this post


Link to post
Share on other sites

Oops- forgot to remove the event polling tests.

Version 1.1 will become unresponsive after a while.

Version 1.1a uses better timers.

(Note: the interaction with the taskbar still is troublesome and causes the module to pause for a while before resuming).

Share this post


Link to post
Share on other sites

Hi, I tried to test your script in an XP machine (will try Vista later - still a 32bit machine) but I am getting and error after which your sample terminates.

"The procedure entry point GetTickCount64 could not be located in the dynamic link library KERNEL32.dll"

PS also your example_full.au3 has this line #include <D:AutoItInputEventversions1.1InputEvent.au3>

Share this post


Link to post
Share on other sites

Thanks LateArrival.

My machine is 64 bits ... I'll look into how to get around this.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

New version 1.2 ... finally worked out how to make the module continue even when window title/taskbar is clicked

Fix #4. InputEvent.au3 does not pause when the mouse button is held down on title bar / task bar.

Fix #5. InputEvent.dll compiled with Windows XP option. AU3 needs to be complied in 32 Bit mode for exe to work.

Microsoft Visual C++ 2010 SP1 Redistributable Package (x86) may be required ... however, I do not have a x86 machine or Windows XP to chack.

Edited by MouseSpotter

Share this post


Link to post
Share on other sites

Tested in Vista and it works very well. Really good work.

Line 292

Func _InputEvent_SetPollInterval($millisecs = 10) ;-> none

$_InputEvent_PollInterval = $_InputEvent_PollInterval

EndFunc

Although 10msec I think is about right anyway.

The example is quite "busy", It might be worth making the mousemove event optional on the debug list. Only because there are some move events generated it is drowning all other event types making it difficult to test.

I was also looking to implement derivative events like doubleclick (i.e. by tracking tick differences between two mousedowns + cancelling a mouseup event when detected a double clieck and finally the distance between the first and the second click). Although I cannot help feeling that this would much faster within the the DLL.

Aside from that I was thinking that I could modify __InputEvent_InvokeEvent to include support to registering objects and methods to generate pseudo-events that will call up event handling methods. I got something along these line working with the SetOnHover UDF and Mailslot to queue the raised events but using this udf processing keys and more mouse events from one single source would be much better. I need to find some time to do a test on this.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Thanks for the feedback!

_InputEvent_SetPollInterval is actually redundant in version 1.2 as the module no longer uses timers.

The examples are supposed to be busy :)

They use _InputEvent_ShowDebug(true) to expose the work that InputEvent is doing.

My thoughts were that the Debug window kept the details visible sufficiently long enough to make this dialog useful. Given your feedback - I'll revisit the dialog to see if I can make debugging the events easier.

I have deliberately skipped Double click as an event. This is because it is a delayed event (click, delay, click) that is best handled by the non-InputEvent code as InputEvent cannot know if a particular object wants to handle two clicks, one double click or a delayed click (i.e.where the delay between the clicks is too long).

I have a few extensions on InputEvent queued up for development.

  • RegisterEvent - allows a program to register objects to one or more user defined functions (e.g. like VB withEvent)
  • NamedEvent - allows a program to name objects which then handle events with function named after them (e.g. like the VB Button_Click() event handler). NamedEvent also will handle event bubbling.
However, these may take some time to eventuate.

Note: InputEvent does not seem to work with WinXP.

I have now built a Win XP SP3 machine and will see if I can get InputEvent to work on WinXP.

Edited by MouseSpotter

Share this post


Link to post
Share on other sites

#14 ·  Posted

Version 1.2a - fixed InputEvent.dll. This now works with WinXP OS (along with VISTA, WIN7, WIN8).

Note: you need to compile AU3 as a X86 version (default from SciTE ; not default foe right click compile from explorer)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Three bugs:

$_InputEvent_EventLastNumber; <-- should be $_InputEvent_EventNumberLast?
Func _InputEvent_SetPollInterval($millisecs = 10) ;-> none
    ; #PUBLIC# ;==================================================================================
    ; Name...........:     _InputEvent_SetPollInterval
    ; Description ...:     Sets the delay between an event being captured and it being actioned
    ;                    Note: setting this too low results in events being missed / reported in the wrong order
    ; Syntax.........:     _InputEvent_SetPollInterval($millisecs)
    ; Parameters ....:     $millisecs
    ;                    | milliseconds delay
    ; Return values .:    none
    ; ============================================================================================

    $_InputEvent_PollInterval = $_InputEvent_PollInterval ; <-- Should this be set to $milliseconds?
EndFunc
$_InputEvent_FocusObject =__InputEvent_WindowFromPoint($mousePos[0],$mousePos[0]) <-- There are two $mousePos[0] statements.
Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

#16 ·  Posted

Helpful. But the attachment has some trojan. Cant download it. Can you upload a clean new attachment.

Thank  you.

Share this post


Link to post
Share on other sites

#17 ·  Posted

RohithMJ,

No problem with the download for me (Avast & Comodo).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

@RohithMJ I also download it, and no virus.

I did thrown away the exe file and have the dll scanned by virustotal (0 virusses)

 

@MouseSpotter great udf, I have never seen this UDF before, thanks.

Edited by nend

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