Serial Input for Windows
Over time I end up writing a lot of little programs and scripts just to get through a particular use-case.
Here’s one of them.
So there’s this thing in Windows XP called SerialKeys which allows people with insane input devices to generate keyboard and mouse events via their PC’s serial (or COM) port.
It’s an accessibility feature, so presumably is for people who enter braille or blink their way through entering text.
This should free up some resources which they can now devote to making the desktop look like half a dozen rectangular blocks.
I recently needed to use this feature in order to get input from a Honeywell 4600GSR scanner, which is one of the few scanners around that can convert convert the 2D Australia Post 4-state barcodes into their constituent bits and pieces.
SerialKeys looked as if it could do the job, but unfortunately only works for COM1 through COM4, which was a pity, because the device driver for this thing registered it at what appeared to be an unmoveable COM15.
After mucking about with the registry for a bit, I ended up rewriting the SerialKeys functionality in a separate application, which, in order to prevent being sued to the ends of the accessible earth, I’ve called “Serial Input for Windows”.
And here it is:
To use it:
- Open the application
- Click ‘Enable Serial Input for Windows’
- Select a COM port, baud rate and other COM settings
- Click ‘Apply’ and acknowledge the ‘Serial Input for Windows is now listening on COMn’ dialog box.
- Whilst this app is in the foreground, any input from the selected COM port is displayed in the application’s ‘Test input’ frame
- If another app is in the foreground, any input from the selected COM port is forwarded to that application
And that’s pretty much it.
If you want it, you can download it here, or grab the source here:
If you do plan to compile the application from the source, you’ll need the free Microsoft Visual Studio 2008 Visual Basic Express
A few gotchas if you do plan to use it:
- It doesn’t implement the full SerialKeys API; in particular mouse control isn’t implemented at all
- The virtual key mapping is fairly primitive; I just created enough of this to get my particular use-case done. So things like shift+character, ctrl+character etc… probably won’t work.
- I haven’t tried it in any OS other than Windows XP, so don’t be surprised if Vista/7/Metro etc consider the whole program a security breach and prevent it from working anyway. Progress.
- Because this is a .NET app, I haven’t gone through the whole maven build rigmarole (I did look at NPanday many moons ago, but there’s a bug in there that prevented me from using it). Although there’s a patch for it now, so maybe I’ll give it another shot.
Some links which were useful in the making of this thing:
- http://support.microsoft.com/kb/260517 – documentation for SerialKeys in XP
- http://msdn.microsoft.com/en-us/library/windows/desktop/ms646268(v=vs.85).aspx – windows keyboard input overview
- http://www.codeproject.com/Articles/2682/Serial-Communication-in-Windows – c serial port example
- http://stackoverflow.com/questions/329865/creating-a-serial-port-in-code-in-vb-net – VB serial port example
- http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.getportnames.aspx – SerialPort.GetPortNames
- http://msdn.microsoft.com/en-us/library/ms646292%28VS.85%29.aspx – GetActiveWindow
- http://msdn.microsoft.com/en-us/library/aa363189%28VS.85%29.aspx – COMMPROP structure
- http://social.msdn.microsoft.com/Forums/eu/vblanguage/thread/41d58def-87cb-41e5-93a4-2ad7d1fb7e0b – VB SendInput example
- http://social.msdn.microsoft.com/Forums/is/vbgeneral/thread/4d60f5f1-add9-4345-a55f-676bf63e4e6e – VB GetActiveWindow example
- http://reflector.webtropy.com/default.aspx/DotNET/DotNET/8@0/untmp/WIN_WINDOWS/lh_tools_devdiv_wpf/Windows/wcp/Base/System/Windows/Input/KeyConverter@cs/1/KeyConverter@cs – KeyConverter source
- http://msdn.microsoft.com/en-au/library/system.windows.forms.keysconverter.aspx – KeysConverter
Note that some of these links may cover fairly basic topics, but I’m not really a .NET developer.
Update 2021-01-09 Source code is up on github:
great job!! exactly what I needed.
Have you thought about making it starting with Windows (just now I have tested it within Win7 and it works very good!)
Can I save configuration somewhere?