Perl-Sensitive Sunglasses | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Some other ways of reading a single keyLegacy and USB RS232 serial portsSee Hardwarebook DB-9 / Hardwarebook DB-25 for pinout. This is a very generic solution. Most operating systems provide some way to read at least one of the status bits of the serial port. You can read back at least one of (D)CD, DSR, CTS, and RI. You can usually set DTR and/or RTS. Often, DTR and/or RTS are already set by the operating system. In idle, DTR and RTS are negative relative to GND, and unconnected inputs are treated like negative inputs. Opening the serial port usually sets DTR and/or RTS to positive, if not, do so manually. Connect a button between DTR or RTS and one of the inputs (DCD, DSR, CTS, RI). When the button is pressed, the respective input reads as positive. In the unlikely case that only bare read and write are available, you can still use the serial port. Connect the button between TxD and RxD, disable receive buffering as much as possible, and send out any data at the highest possible speed. As long as the button is pressed, you will see incoming data. The trick here is that humans need several milliseconds to press and release a button, during that time, several bytes travel from TxD to RxD. This trick should work with all serial RS232 ports found on a PC, either build-in or USB. Legacy PC joystick inputSee Hardwarebook for pinout, for details. Connect a button between GND and one of the four button inputs. When running DOS, you simply read port 0x0201 and look at bits 4 to 7 to read the button inputs. Windows should support that interface, too, but I have no idea how to read it. I'm guessing that there is some device-independant DirectX API. Linux shold support that interface, too, using the event system (I guess). USB adapter for legacy PC joystickThe same idea, but a different Windows driver. No DOS support. Windows and maybe also Linux should treat it like a legacy joystick interface. Legacy Parallel portSee Hardwarebook for pinout, https://wiki.osdev.org/Parallel_port for details. There are five handshake / status lines (/ACK, BUSY, PAPEREND, SELECT, /ERROR) that accept a button connected to GND. You probably need to get port-level access on Windows and Linux to read the status bits. USB parallel port adapters may be even harder to work with. Raspberry PiIf you use a Raspi, have a look at the work of stevieb, especially RPi::Pin, and https://pinout.xyz/. Just connect the button between GND and a unused GPIO line, then configure the pin as input with a pull-up. The pin will read as 0 while the button is pressed, else 1. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) In reply to Re: Morse input from keyboard
by afoken
|
|