Go Log Keys
Simple key logger written in C and Go.
Its intended use it to register some keys (from a JSON file or something), and
register key events (press/release) through a WebSocket to my
stream overlay, so it can display
which keyboard keys (mapped to a controller or something) are currently pressed.
Logging on Windows
Windows allows setting a callback for global keyboard events. However, it must
have been loaded from a DLL, instead of from the current process...
./winDll/logger.c
implements the callback, keyCallback
, and a function
to retrieve all keypresses, pop
.
Note that (from this
StackOverflow answer)
that sleep
etc blocks the callback... So, that DLL also has a function,
wait
, that creates a dummy window, which may be used to keep the logger alive.
With mxe installed, you may compile the DLL and the test with:
export CC=x86_64-w64-mingw32.shared-gcc
${CC} -shared -Wl,-soname,logger.dll -Wl,-export-all-symbols -o logger64.dll winDll/logger.c
${CC} -o test64.exe winDll/test.c
Note that I use the 64-bit MinGW compiler... I could only get this to work by
using a 64-bit DLL along with a 64-bit test application (in my 64-bit system).
However, I believe that injecting a 32-bit DLL into a 32-bit application in a
64-bit system should be possible...
Building the Go part should be quite straight forward... Try to build it and
go get
anything that fails:
go get -d github.com/pkg/errors
go get -d golang.org/x/sys/windows
go get -d github.com/SirGFM/GoWebSocketProxy/websocket
GOOS=windows GOARCH=amd64 go build
Logging on Linux
Be sure to install python3-xlib
! Other than that, this should work out of the box.
go get -d github.com/pkg/errors
go get -d github.com/SirGFM/GoWebSocketProxy/websocket
go build
Resources
Non exhaustive list of resources used to write all this: