For the GUI approach, give https://github.com/go-vgo/robotgo a try. It claims to support Windows, Mac, and Linux(X11).