Log Keyboard and mouse activity Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Log Keyboard and mouse activity

27 Jul 2021, 04:21

Hi
I have a problem with a rather complex ahk script: while in principle it works, there is a strange side effect in one other program that I don't find where it comes from.

Is there a program that can produce a complete log of all keyboard and mouse clicks, including everything generated by a script (I am only interested in mouse clicks, not in mouse movements). That would be of very great help, I would be glad not to have to write it myself...
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Log Keyboard and mouse activity

27 Jul 2021, 08:21

Code: Select all

Global logFile := StrReplace(A_ScriptFullPath, ".ahk", ".log")
clik("R", 100, 100)

~LButton::
~RButton::
~MButton::
~XButton1::
~XButton2::log(A_ThisHotkey)

F3::Run, notepad "%logFile%"

log(button) {
 MouseGetPos, xpos, ypos
 WinGet, proc, ProcessName, A
 button := RegExReplace(button, "(~|Button)"), proc := StrReplace(proc, ".exe")
 FileAppend, %A_YYYY%/%A_MM%/%A_DD%`,%A_Hour%:%A_Min%:%A_Sec%`,%proc%`,%button%`,%xpos%`,%ypos%`n, %logFile%
}

clik(button, x, y) {
 MouseClick, %button%, x, y
 log(button)
}
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Log Keyboard and mouse activity

27 Jul 2021, 14:57

Hi Mikeyww!
Thank you, this was the easier part, as there are a very limited number of mouse buttons. :)

I have solved my original problem, so there is no more acute need, but there were already several situations where I would have wished to have such a logger.

You can easiliy capture actual characters using "input", and there are several ready made programs in the internet, some of them even freeware, which do this. But neither "Input" nor these available programs react to keystrokes, they only log characters. So the log does not show that for example {shiftlock} was pressed, nor does it show {del} {esc} or {left}. That is however crucial when I am debugging some ahk scripts.

What I am looking for is a way to log all keybaord and mouse events, no matter if a keyboard event produces a character or performs another function. I did not need Mouse movements for my last problem (and most of the time won't need them), but generally such a logger should also log mouse movements. AHK has builtin keyboard and mouse hooks, is it possible to attach to them in some way?
Last edited by braunbaer on 27 Jul 2021, 15:20, edited 1 time in total.
ahk7
Posts: 574
Joined: 06 Nov 2013, 16:35

Re: Log Keyboard and mouse activity

27 Jul 2021, 15:09

Fairly certain posting keyloggers are against forum rules. @gregster ?
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Log Keyboard and mouse activity

27 Jul 2021, 15:20

Right, key loggers are available elsewhere. Input can be used to capture any key; see the documentation for an example there. That's about all I can offer myself.
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Log Keyboard and mouse activity

27 Jul 2021, 15:36

Well, if you want to spy on somebody elses computer, there are readymade keyloggers available, but they log characters, not keyboard events. For that purpose, keyboard events are of no interest, it would just complicate the examination of the logs.
gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: Log Keyboard and mouse activity

27 Jul 2021, 15:56

So far, I don't see code with malicious intent here (based on my subjective concept of a key logging malware, as we don't have a clear definition of it in our rules). There is probably some scattered code on these (and the archived) forums which is more problematic. But this code is still sufficiently trivial, imho, to allow it, based on what AHK offers by default.

A software like AHK which hooks mouse and keyboard is obviously prone to be abused as a software that logs keys - that's probably a main reason why we have problems with antivirus false positives for autohotkey.exe. But these features are already built-in, and are used for a lot of legitimate reasons. If you look at the KeyHistory, A_ThisHotkey, A_PriorKey and so on, you will even see some built-in key-related logging, not even speaking of our Inputhook(). All this can easily be written to a file.

I have removed clearly malicious or dubious code in the past, and will do so again. But so far I would say, this is allowed.
That could certainly change, depending on how the code or the topic develops.

@ahk7, I see your point, though, thank you for voicing your concern. There is obviously a grey area, but one that always existed for us.
I will also make a short post in the staff forum, linking to this topic, so that other team members will notice it and can act if they feel differently about it.
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Log Keyboard and mouse activity  Topic is solved

27 Jul 2021, 18:35

Just found the solution. Stupid that I did not notice that earlier.
The AHK mainwindow has a built in mouse and keyboard logger that can show the last up to 500 key events. In fact, that is all I need.
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Log Keyboard and mouse activity

27 Jul 2021, 20:01

Thank you, that's helpful too
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Log Keyboard and mouse activity

28 Jul 2021, 13:46

Im all for AHK but there is a better built into windows answer
start run "steps recorder"
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Log Keyboard and mouse activity

28 Jul 2021, 14:58

Nice, but does not record keystrokes :)
Steps Recorder doesn't record anything you enter. If what you enter is an important part of the steps, you can add comments while recordin

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dunnerca and 126 guests