[Tutor] push a keyboard button to run a function

DL Neil PyTutor at danceswithmice.info
Fri Apr 10 19:53:36 EDT 2020


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


More information about the Tutor mailing list