Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard and Mouse logging
Hi Gintaras,

I would like to log my computer activity.
I've got basic logging of the active window working ok, with a timer-function (functions below).

I would like to log keyboard and mouse events as well.
Can you point me in the right direction to get started with this.
I've looked at ifk and RealGetKeyState, but they check for a single key.

How can I trigger a function for any keypress or mouse click?

Thanks again for Quick macros and your fantastic support.
John Anson

PS: Logging function that is called by a timer each second:
;; Log active window if changed from last time called
int w
int+ prevWin_mu
str winTitle
str+ prevWinTitle_mu

if w = prevWin_mu and winTitle=prevWinTitle_mu; ret

str line, winExe
long+ previousRuntime_mu

long elapsed = elapsedms(previousRuntime_mu)/1000

;; Append time in previous window to previous line
line.from(" " elapsed "[]" _s.time("%H:%M:%S") " " winTitle " (" winExe ")")

;; Log to file
str logfile.from("c:\temp\usage\" _s.time("%Y%m%d%a") ".log")
line.setfile(logfile -1 -1 )
out "Error writing to logfile: %s: %s" logfile _error.description
out "line=%s" line

;; Return the elapsed time in milliseconds since last called, or zero the first time called
;; Optionally pass the previous time to calculate the elapsed time from
;; - if passed, the previous time variable is updated to the current time, by default
function'long [long&previousTime] [DoNotUpdatePreviousTime]
;; previousTime is a reference
msg &previousTime ;; Zero if optional parameter not passed
long+ elaspedmsPrevTime
long elapsed

long now = GetTickCount ;; milliseconds +/- 10
now=perf ;; microseconds

& for reference that holds address, but references value
Make t reference "previousTime" parameter if specified, else "elaspedmsPrevTime"
long& t=iif(&previousTime previousTime elaspedmsPrevTime)

if t=0; t=now ;; Happens the first time called

;; Not sure when I64 is required?
out "%s %I64i %I64i %i" "elapsedms:" elapsed t now

if DoNotUpdatePreviousTime=0
t=now ;; update "previous time" variable
ret elapsed
Read in MSDN Library about SetWindowsHookEx. Use low level hooks. Some examples also available in the forum. Search for BlockInput2.
Thanks, Gintaras.
The BlockInput2 functions are an excellent example of what I would like to do.

PS: How far away are email notifications for post replies on teh boards?
Email notifications probably work only if you log off everytime. I cannot fix this. See also:
http://{deleted post}

Forum Jump:

Users browsing this thread: 1 Guest(s)