Jump to content

UDF Input Event Capture - Mouse & Keyboard


MouseSpotter
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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
Link to comment
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).

Link to comment
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>

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 years later...
  • Moderators

RohithMJ,

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

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

 

Link to comment
Share on other sites

  • 3 years later...

NEVER MIND. I'm using Accelerators now and it's working perfectly. I'd considered them before, but I mistakenly thought you had to specify a moderator character, such as "!" for Alt. But they work just fine with ordinary, single characters.  I'm going to leave my previous post here in case MouseSpotter sees this and possibly create a 64-bit version of the DLL.

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 

Hey @MouseSpotter or anyone else: When I try to use this UDF here in July 2019 under 64-bit Windows 7 Pro, I get a popup window reading: "Unable to open InputEvent.dll / Program will terminate".  I'm sure that's because I want to build a 64-bit executable, whereas MouseSpotter states that you must build only for 32-bit.

Is the source for that DLL available so that it could be made 64-bit compatible? My guess is that the answer is NO because having it might allow an unscrupulous programmer (and sadly, there are vast numbers of them) to craft a key logger, which is quite justifiably verboten. But how about if some trustworthy person, such as one of the AutoIt developers or moderators, would be allowed access in order to build a 64-bit version of the DLL?

Because I really want a 64-bit executable, if it is at all possible...  Or is there a different technique/UDF that would accomplish what I need? Which is simply to capture one or more of a small set of command characters when any list view item  (using Melba23's UDF) is selected (only when my GUI has focus, of courese). For example, entering a "p" means "play" and a space means "pause" and so forth. A context menu or anything else is quite undesirable in this case.

Thanks!

 

Edited by Mbee
Revised issue
Link to comment
Share on other sites

  • 3 months later...

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