A
A
Andrey Turyansky2013-12-28 21:24:18
Python
Andrey Turyansky, 2013-12-28 21:24:18

How \ than to track the pressing of the arrow keys, etc.?

Hello.
I need to somehow track the pressing of the arrows and, depending on the key pressed, send a command to the port.
Once upon a time, I did something similar in VB via winAPI, now I use Debian - this option does not work.
1) Found a way through

tty.setcbreak(sys.stdin)
ord(sys.stdin.read(1))

But after these lines, the console in which the program is launched just goes crazy and does not come to its senses even after the end of the program. Most likely, I'm doing something wrong, but I did not find a sane description of these functions - I just copied from some example.
In addition, sys.stdin.read (1) when the arrow is pressed gives a 3-byte code, I did not understand how to process it, because the code is issued in the form
XX
YY
ZZ

In 1 line it is impossible to deduce.
Povtykal in 1.5 examples found in Google, scored, began to look for other options.
2) I found examples using pygame, I liked it, figured it out, everything turned out to be quite simple, however, I can’t find normal documentation on it (maybe you can tell me what to read, you can also in English, but it’s better if translated).
The fact is that I don’t need all the functionality of pygame, I just need to analyze the work with the keys.
Maybe there are some simpler tools?
PS Is it possible to somehow hide the program window during operation, which is created by
pygame.display.set_mode( ((0, 0)), because I don't need the graphic part?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
i0ngunn3r, 2014-01-17
@i0ngunn3r

What application, console, with graphics?
Have you tried using curses ( stdscr.getch() )?

A
Andrey Turyansky, 2014-01-21
@warezzzok

The application for controlling the machine via Wi-Fi - catches pressing the button, sends the command code through the socket, at the other end the server part throws bytes into the uart to the controller of the engines. In principle, I already did it on pygame, though during initialization a window opens, which should be in focus. In fact, you can leave it like that - I will do some kind of animation there later, if not lazy.
curses (stdscr.getch()) didn't try it - didn't know about it. I'll try, thanks for the advice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question