I'm going to copy this largely from a post of mine on reddit, because I'm inhibited by a broken wrist on my dominant hand:
Due to that broken wrist I've been reduced to one-handed hunt'n'peck. And the solution to that is what I'm trying to work out. What I want to do is set up a system event that - while happening - switches my keyboard to a horizontally flipped layout.
Ideally, I'd like to place a game controller on the floor and be able to flip my keyboard by pushing a button with my toe.
Using a PC and running Linux Mint 17, with a KDE 4.13.2 desktop.
Bonus: At work I use a Macbook Pro with an up-to-date MacOS and would like to do the same.
Also note that I'm using a Dvorak keyboard map, and can touch-type that, but not on a QWERTY, so I'll have to stick to Dvorak for this to work.
So, in KDE, I can see that in System Settings -> Hardware -> Input Devices -> Keyboard, I have a "Switching to another layout" option. Unfortunately, all of the options involve keyboard events.
Also under System Settings I can go to "Common Appearance and Behavior" -> "Shortcuts and Gestures" -> "Custom Shortcuts", and capture events to run anything I want. Unfortunately, it too only captures keyboard events. At that point I'm quite stuck.
I've no Idea what to do for MacOS, But haven't really tried either; trying to get my home machine going first.
I also found a partial solution from none other than Randall Munroe of XKCD fame. I'll have to edit that to match my Dvorak layout, but no big deal. The problem is that it still depends on a keyboard event. Any suggestions on how to trigger that key signal upon clicking a controller button?
As per dirkt's suggestion, Here's the output from evtest on the down event:
Event: time 1496762047.394575, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90002 Event: time 1496762047.394575, type 1 (EV_KEY), code 289 (BTN_THUMB), value 1
And of course the up event is the same, but with a "BTN_THUMB" value of zero.