# Use toggle Switch to Send Keystroke

I'm working on a budget simulator build, and I'm planning on have a selection of switches or devices that work in a "Toggle" manner, i.e. latches in the on position until moved to the off and vice versa.

The issue I face with this is that most of the commands I want to control are normally controlled by a keyboard, and expect a momentary input. I'm planning on using an old keyboard as my input device, taking it apart and soldering leads onto each of the key contacts. Im hoping for 2 functionalities:

1) When the toggle switch is flipped from off to on ONLY, allow a momentary connection across the keyboard contacts.

• found this link but uses double pole switch, need to be able to use single pole

2) When the toggle switch is flipped from off to on AND from on to off, allow a momentary connection across the keyboard contacts.

• The link above has a solution but same issue as above, plus it requires relays, hoping to do this with small, inexpensive components

• This link i think has a solution, but I know nothing about logic gates and my electrical expertise is limited t best, trying to figure what connects to the 3 leads (assuming the arrow is ground, the left is the positive contact and the right is the negative contact?).

I tried simulating on falstad.com and only get an inital pulse on, nothing off or on subsequent flips. The voltage on the two comparator legs of the gate both read the same voltage.

Any help would be much appreciated

• Welcome to EE.SE, James. Can you post images into your question so that we don't have to follow three links just to understand it? – Transistor Aug 27 '19 at 16:02
• I think the easiest way to do this would be to route the buttons into an Arduino and have the Arduino hooked up as a USB HID keyboard to the computer. Add all the logic you want at that point. – Ron Beyer Aug 27 '19 at 16:07
• Arduino USB Keyboard Reference – Ron Beyer Aug 27 '19 at 16:15
• Updated with pictures, didn't include the first time as it makes the post quite long. – James Aug 27 '19 at 16:47
• Ron - I appreciate the idea, was something i had looked at in the past. I only have brief experience with arduino so would take some learning. I was thinking that might also be quite a bit more expensive than some resistors, caps and gates? I'm talking in the range of 30-40 inputs, not sure what size arduino i would need, and when i would start needing to build a matrix, etc. – James Aug 27 '19 at 16:52

The last solution you have linked can work as expected for your application. I simply ran it through falstad with normal XOR gate and it works as expected. But XOR gate with Schmidt trigger input is highly recommended.

When the toggle switch is flipped from off to on AND from on to off, allow a momentary connection across the keyboard contacts

Any level change on the input pin (OFF to ON or ON to OFF) creates a short pulse on the output Pin (output of XOR Gate) The output can be then used to drive a MOSFET or other similar component to close the keyboard contacts.

The pulse width can be varied by varying the value of $$\R1\$$ and $$\C1\$$. Exact values of $$\R1\$$ and $$\C1\$$ can be attempted to calculate based on datasheet of the EXOR gate used. as of now, trial and error method should work.

A simple LTSpice simulation

Green is input voltage, RED is voltage across capacitor and Blue is the output voltage.

• Thanks Umar. I added an image from my Falstad simulation in the original post. I cant get it to pulse more than once. Am i missing something? – James Aug 27 '19 at 19:58
• Thanks again, not sure why it wont replicate on falstad but worth a shot in reality for a couple bucks. Appreciated! – James Aug 28 '19 at 12:10
• Please add a voltage Source in falstad. Set frequency to 10 Hz, a square wave signal. It will work – User323693 Aug 28 '19 at 12:17