Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Some other ways of reading a single key

Legacy and USB RS232 serial ports

See 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 input

See 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 joystick

The 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 port

See 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 Pi

If 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
in thread Morse input from keyboard by pierrot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found