Archive Keyboard Entries in Python

0

I am building a code to hold any command made by the keyboard, they will be published in a ROS structure topic to control a mobile robot. I'm not very familiar with Python, the most I've achieved regarding data storage was the code below ... For example, let's assume the left directional is typed, I need to store it it was pressed to only inform the robot he should move in such a way.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
arq = open('/home/lucas/Área de Trabalho/robosmoveis2018/dados.txt', 'w')
text = """
Lista 
---
1
2
3
"""
arq.write(text)
arq.close()
    
asked by anonymous 09.08.2018 / 01:56

1 answer

2

One of the easiest things to use in Python to read the keyboard directly is the " pygame library."

It is possible to get information about the keys pressed in real time (without having to wait for the user to type "enter") and to get information about the arrow keys and others, which using only the I / O terminal is very complicated to do.

Pygame would be cool because in addition to giving control over the keyboard reading and a simple interface to draw in a window, leaves you in full control of the program - then the same program that reads the keyboard can exchange data with the external device robot, in case), and even draw some return in the window, to the program user.

But you'll need to learn a minimum of Python to get things done - it's an easy-to-average complexity project, and you can not solve it by asking all the steps, or by trial and error. If you read English, I suggest following the official tutorial at python.org - sorry, see the documentation in Portuguese / translated here: link

    
09.08.2018 / 15:25