Showing posts with label keyboard. Show all posts
Showing posts with label keyboard. Show all posts

Monday, 22 June 2020

Context-sensitive macro keypad

I've been doing quite a bit of 3D work recently for both 3D printing and VR software development.

The main software that I use for 3D work are OpenSCAD and Blender.

One annoyance I have is that the short cut keys each use for standard things such as scale, rotate, move, etc. are all different, which makes switching between applications more awkward than it need be.

So my latest electronics project is to create universal short cut keys - a physical keypad that has single button presses for those functions, but then translates them into the relevant keyboard/mouse presses dependent on which application has focus at the time.

The hardware
As we're still under lockdown due to COVID-19, I'm restricted to using only components and tools I have got at home, like with the USB Switch project.

The keypad itself is this mechanical key switch tester.



Unfortunately the eighth switch was lost some time ago. I'll leave the gap there as potential room for expansion in future though.

The controller is an Arduino Pro Micro. I thought about using a different microcontroller, however the real sticking point was my lack of a spare USB to serial adapter.

The Pro Micro helps keep the overall form factor nice and compact, whilst keeping the programming side of things straightforward.

I picked out some LEDs to backlight the keys as there was spacing for them, and the keycaps are translucent. I tried to find all different colours, but my inventory didn't allow for that, so there's a couple of duplications.

The rest of the hardware is just some diodes and resistors, a bit of perfboard and some scavenged wires.

The hardware is wired up like so:
Quite simply, there's two matrices, one for the switches, and one for the LEDs. Because of the missing key, one column in each only has three connections.


The case is just some plastic container that would otherwise have been trash. It wasn't a perfect fit so required some Dremel-based customisation.

The Firmware

The Arduino will stay set up as a USB to Serial device rather than as a keyboard because there needs to be bi-directional communication - the Arduino needs to also receive input from the application in order to control the lights.

This post was a useful resource when putting together the matrices.

The full source is available in the project on GitHub.

The Software
The software is a java desktop app that communicates with the Arduino using jSerialComm. It controls which keys are 'set' and indicates this with the LEDs.

The interfacing with the other applications comes from a thread that uses system calls to the 'xdotool' linux command, reading in the output of that command which is the name of the current window that has focus. There's room here to make the application multi-platform, by implementing a similar Windows command in something like AutoHotKey.

If the window matches the defined rule set, the relevant keys are highlighted and a thread monitors serial input. If that key is pressed, java built-in Robot class sends the relevant commands to the application.

As with the firmware, the source is available on GitHub. It's in a pretty simplistic state at the moment due to the one-week time limit I've placed on these lockdown projects, but there's room to expand and improve in future.

Tuesday, 31 March 2020

Simple USB KVM adapter

With the shadow of Covid-19 hanging over our heads, I, like many others, am now working from home.

Having my home PC set up right next to my work set up has been a bit of a pain - two keyboards and two mice competing for desk space. Plus the work keyboard and mouse was a spare wireless set I had kicking about - not really comfortable enough for long-term use.

The monitor I attached to my work laptop was the second monitor I use for my home set-up - thankfully it has two inputs, so that's an easy one-button switch.

I wanted to use my main keyboard and mouse with my work set-up as well as home, but didn't want to unplug/replug each time.

I also wasn't too keen or just ordering a USB KVM adapter (a device which lets multiple computers share keyboard, mouse and monitor), as recently some of our local postal and delivery works have fallen ill, and so I'm avoiding any non-essential deliveries - I don't like the idea of putting others at risk for stuff that's a 'nice-to-have'.

So I figured I'd look through the electronics pile and see what I could piece together.

I did have a PS/2 KVM that I was hoping to adapt, but having read the datasheet for the bus IC that underpins it, it had a low maximum current rating - it might have been fine for just a keyboard or a mouse, but the keyboard I want to use has a backlight, audio controller and USB hub built in, and a brief look with

lsusb -v

showed that they would easily surpass that maximum rating.

Software options are also a no go - whilst they'd been fine when working locally, they won't work with my work's VPN, and the IT guys have enough on their plate without me adding to it.


So, I ended up going for the simplest of options. I had some relays - they were obviously meant for higher power application than this, but found that wired up in parallel, 5V was enough to trigger them. I was planning on powering it from a USB port, so 5V was the target.

A rough schematic of the switch


Unfortunately they had a weird footprint that put one of the pins in between rows on standard perfboard, so I ended up dead-bug soldering them.
A diode across each of them to prevent voltage spikes from the coils, some USB extension leads and a switch later, and I had a 4 channel switch.

I was a bit concerned at the lack of a protective load on this circuit, but adding any additional resistance from the power to the relays would prevent them from switching - as they're really designed for higher power applications, I reason that the coils have enough power requirement to prevent a short.

I have ran it for a few days under close observation and seen no temperature / magic smoke issues, and it's only ever powered when I'm sat right in front of it, so it should be fine. Obviously if this wasn't a "whatever's at hand" project, there'd be much more elegant ways of doing this (bus IC, 4 pole switch, more appropriate relays, etc), but here we are.

A gratuitous amount of cable ties, double sided tape and an old business card box provides structure and an enclosure. I'll probably tidy it up a bit more later as time allows, but for now it's enough that it works.


Monday, 11 August 2014

Analog pedal to USB keyboard


A lot of my electronics junk box consists of old videogame peripherals, which are often tricky to re-purpose because of proprietary connectors, peripherals, etc.

These pedals, for example, connect to a Playstation steering wheel by a fairly normal 9-pin serial connector, but the wiring isn't standard. Even if it were, most modern PCs no longer have serial ports, so a serial to USB adapter would be needed, and a software solution to make the input useful.

What I'm really after is a drop-in system, that can provide input as if it were a regular keyboard or mouse. The easy way out would be to use a microcontroller to emulate one of those devices, but I want to avoid throwing one at every problem, so I'm going to opt for only using discrete components and a scavenged keyboard PCB.

I'm going to re-purpose this keyboard PCB from the phone scanner project that I did a while ago.

The pedals themselves are essentially just a couple of potentiometers, so in it's simplest form, the contacts for a key could be wired to the pedal. This would mean that as the pedal is pressed, it will reach a point where the resistance is low enough for the signal to pass, however this is quite a simplistic option.


It also seems a shame not to make some use of the fine control of the analog input, so what I have in mind is a two-stage trigger type system - so that a light press of the pedal completes one key, and a complete press sends a second key. For example, a light press could be 'Ctrl', and the full press 'X', to create a pedal for the standard Cut shortcut.

So what's needed is to find a way to create a threshold for when to close the keyboard circuit and trigger the buttons. In order to so this, we can use a low battery circuit, such as the one shown here.

Rather than wait for the power to drop though, we will be using the pedals' potentiometer in place of R4 in the diagram. As the voltage will remain the same, using the pedal to change the low voltage level will change the sensitivity of the circuit, so that when pressed, the LED is triggered. We will also replace the LED in that circuit with an optocoupler, connected to the keyboard matrix for the key that we want.

To create the second stage of the trigger, another copy of the circuit is created, but using a higher value resistor in place of R3, and sharing the same R4 (the pedal). This one will trigger when the pedal is pressed further.
The circuit, with a test potentiometer in place (the upside-down PCB just contains some screw terminals for attaching the potentiometer - see right) Each pair of leads on the left go to the respective terminals on the keyboard PCB (below)
The screw terminal on the underside (on a separate PCB as I scavenged it from the junk box)

The keyboard PCB. The old IDE cable is there to make it easier to patch together the key matrices - In the picture above the leads from the pedal circuit board are connected.


Finally, power is added to the pedals from the keyboards USB connector - see left. This is sufficient to power both the keyboard and the pedal circuit


I have currently only done this for the right-hand pedal, but the same process could just as easily be done for the left (perhaps for other modifier keys - one shift, one ctrl etc).


A test of the pedal in various applications showed it to work, and has proved its usefulness for tedious key combinations in games (such as toggle run/slide etc)