LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 11-20-2011, 01:51 AM   #1
Senior Member
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Rep: Reputation: 50
button to control software

Hi All,

I am posting this in Linux-Hardware, but mods, please feel free to move it if it should be elsewhere.

The objective
I want to build a physical button that I can connect to the computer so that when pushed it starts recording a file, then when pressed again (or switched, whatever, the details of the button don't matter) the recording stops and the file is saved with a file name (the date, etc.)

I realise this will require software wrangling as well has hardware construction.

The ideal, perfect solution is that the operators of the computer be able to interact with the recording software, but this has proven to be difficult. they often forget to record, so a big red button in front of them might help.

What I'm asking for
I am struggling to find the right search terms so I can find what I want.

I am quite happy to launch out and pull together different tutorials to make this project work- I'm not looking for a hand holding step by step guide (though if one even exists that would be amazing!).

If you could help me to find tutorials, articles and howtos that would be great.



ps: this is for a windows machine (boo) using Goldwave but I figure once I know what I'm doing in a linux/unix setting which is more 'hackable' (not the cracker sense, obviously) I can work out how to do it on the windows box.

Last edited by titanium_geek; 11-20-2011 at 01:52 AM. Reason: closed open formatting tag
Old 11-20-2011, 02:53 AM   #2
LQ Guru
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Check out the Arduino - Might be what you are looking for, if you want to go the super simple route.

Now as far as the "simplicity," are you trying to create a USB device? Or do you want to create a serial device? If it is something as small as just a button, you could wire of a button, via a serial connection, then just use a serial-to-usb converter to convert to a USB plug, etc... To use under linux, see here -

The following link is one of many sites found on google for interfacing simple hardware to your computer - (just an example...)

Let me know if any of that helps!


Old 11-20-2011, 03:08 AM   #3
Nominal Animal
Senior Member
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 944Reputation: 944Reputation: 944Reputation: 944Reputation: 944Reputation: 944Reputation: 944Reputation: 944
Get a Teensy USB Development Board or an equivalent microcontroller USB stick. Just make sure it has a native USB interface, not a serial-to-USB converter like most have.

For the Teensy, there is even an USB keyboard example. Because it has a native USB interface, it can be any kind of an USB device. In the example, it is configured as a USB keyboard. This is done at the hardware level; there is no driver software or anything involved. It will work on any operating system that supports USB keyboards.

All you need to program it is a mini-B USB cable and gcc-avr. It is both programmed and powered via the USB connector. You can use the digital I/O pins for a matrix (WR buttons for W outputs and R inputs using only W+R digital I/O pins, buttons/switches, diodes, and resistors), and/or up to 12 or 8 (depending on model) analog I/O pins for sliders or rotary controls. There are also Hall effect sensors for magnetic sensing, and capacitive and inductive touch sensors for touch buttons you can easily use, if you need to hide the button in plain sight (say, inside your table surface, for example).

Standard push buttons or microswitches should work well for a simple button. For an example, see the Reddit Upvote Button.

Look at the USB HID specs or Microsoft documentation which scancodes you want your buttons to generate (search the net for USB scancodes for example). Personally, I would have it send different scancodes for odd and even keypresses. In Linux, I would use a small program to send a HID message -- similar to force feedback messages on gamepads -- that would light up a LED on the button when the recording really starts. You can supply say 10 to 15 mA current to a LED using an I/O pin from the Teensy just fine; just pick a suitable resistor for the LED to limit the current.

On the software side, you'll need to assign a keyboard shortcut (for the scancode you selected), to run the start-recording and stop-recording scripts. All Linux desktop environments (Gnome, KDE, XFCE, et al.) support keyboard shortcuts, usually with an easy-to-use interface under Keyboard Settings or Application Shortcuts. I don't use Windows, so I don't know whether you need some extra software or if it provides suitable functionality out of the box. (I don't really care about Windows at all, to be honest.)

In Linux I would use ~/.mything/ directory to hold the current recording, with ~/.mything/recording-pid containing the process ID of the running recording process (usually arecord ). That way the stop-recording script would only need to send an INT signal to that pid. The start-recording script would run for the entire duration of the recording. It would simply notice the recording has ended, and move the completed recording to its final location, naming it properly. I believe these two scripts would need just a couple of dozen lines of code in Linux, even if written to be compatible with both ALSA and Pulseaudio audio systems. To enable it for a user, you'd only need to make sure the two scripts are installed on the system, then set up the two keyboard application shortcuts.
Old 11-21-2011, 08:04 AM   #4
Senior Member
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
Thank you all for your very helpful responses!

One way to attack it is to have the button register as a keyboard short cut, then use that to launch a script. Any thoughts on the practicality of adding keyboard short cuts?

edit: answering my own question: (for windows)

So: I set a keyboard short cut, send the keyboard short cut when the button is pressed to open the program, send the ctrl-n and ctrl-f9 to start recording a new file, then when button is pressed again stop recording.

I have to research how to send key-combinations via teensy, but should be easy.

Thanks so much!


Last edited by titanium_geek; 11-21-2011 at 08:51 AM.


button, control, record

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Control Skype Calls with Bluetooth Headset Button in Linux LXer Syndicated Linux News 0 07-12-2010 05:30 PM
Tip: how to turn off monitor with a software button ahz Member Success Stories 1 06-07-2005 08:53 PM
How to control the power button in redhat 7.3 like windows XP - please helps ! kikkubey Linux - Hardware 2 10-05-2004 01:48 AM
Why does my version of drakconf, not have a 'software management' button? pdmackenzie Mandriva 2 09-15-2004 08:27 PM
Moniter button/speaker control Kathleen Linux - Newbie 1 05-22-2003 09:00 PM

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration