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.
Enjoy 🙂
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?
Hi. Thanks 🙂 Glad you liked it.
There’s no automatic startup option yet, but you can add the program to your Startup folder, and it will start every time you log in (which isn’t the same as starting the program as a service, but that may be good enough for now).
There’s a set of command-line options to the program that you can use to pre-populate the fields in the main form; they are:
e.g. something similar to the command line:
C:>"C:Program FilesSerialInput4WinSerialInput4Win.exe" -port COM3 -baud 9600 -data 8 -stop One -parity None -flowcontrol None
NB: I’ve added an installer to this package which I haven’t uploaded to the site yet; I might also add some auto-startup options and allow the end-user to save the settings in the registry before I make it public.
great, thanks a lot!
Yes, definitely you should add some installer as there are just a few solutions for serial readers 🙁
However yours is working great!
One more question – is there an option to add n or (ex. enter key) to end of scanned string?
Hi milan.
Unfortunately, I don’t have the scanner here any more, so adding the newline at this stage would probably be a bit buggy without it.
Also, looking back at my dev notes, the 4600GSR added a newline itself anyway so I didn’t need it at the time.
I guess it wouldn’t be too difficult to go into the code and set up a timer to automatically generate a carriage return if no input had been received n milliseconds after the last character is received.
hy knoxg,
ok, I’ll deal with break row somehow. Bar code which I currently have gives me some headache anyway.
About auto start here is little .cmd file which I made and work like a charm once added in startup list:
@echo off
start /MIN I:pathSerialInput4Win-0.0.1.exe -port COM3 -baud 9600 -data 8 -stop One -parity Mark -flowcontrol None
exit
Once again, great job!!
Cheers
Hi,
-port COM1 -baud 9600 -data 8 -stop One -parity None -flowcontrol None
works great !
I run it from a batch file (minimized). Is it possible to get rid of the confirmation message when it’s loaded ?
Greetings,
Bart Dikkeboom.
Great work, but I experienced, both on Windows 7 and on Windows 11, an unability to send strings from a laboratory weighing balance communicating through 9-pin serial port, to the application having the focus (while the within-app grabbing for test purposes was working 100% ok). In such cases, a good alternative is provided by the OPTICON company and its “Serial to Keys” software: http://wiki.opticonusa.com/techsupport/en/Serial_to_Keys. Worked fine in my case (both Win 7 and Win 11), for the very same purpose as this “Serial Input for Windows”.