[Tutor] push a keyboard button to run a function

Michael C mysecretrobotfactory at gmail.com
Fri Apr 10 20:06:17 EDT 2020


Oh, I am not trying to wait for a keystroke while the rest of the program waits!

I think I need to be able to push a key and change a variable from true to false and back and then when the next time the program checks that variable, the program does something.

Sent from my iPhone

> On Apr 10, 2020, at 4:54 PM, DL Neil via Tutor <tutor at python.org> wrote:
> 
> On 11/04/20 11:16 AM, Alan Gauld via Tutor wrote:
>>> On 10/04/2020 23:11, Chris C wrote:
>>> I am trying to invoke a function in my python code by using a keyboard
>>> keystroke.
>> You need to tell us more.
>> Is this a CLI program or a GUI? If a GUI which toolkit?
>> Tkinter? wxPython? other...
>> If a CLI which OS? If it is Unix like then the curses module
>> is your friend.
>> If its Windows the msvcrt module will help.
>>> Alternatively, I need to change a variable's value from true to false and
>>> false to true everytime when I push this button,
>>> 
>> variable = not variable
>> will toggle a boolean between true/false.
>> But we need more context information to answer fully.
>> Ideally some code (even if it doesn't work) to see what
>> you are attempting.
> 
> 
> Concur.
> 
> If the "keystroke" is/can be the Enter key, then an input() will do.
> 
> There is a keyboard library in Pypi (https://pypi.org/project/keyboard/)
> 
> See also curses, Pygame, and more...
> 
> -- 
> Regards =dn
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list