I am wondering about bow to implement two-key combinations in Python. I am utilizing the turtle.onkey()
function since I am using turtle graphics, but it seems like it is not very versatile, as I cannot find a way for it to take key combinations. So, is there any other way to implement key combinations in python? Any help regarding this issue is very much appreciated! :)
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
I use pykeyboard ( with Python 2.7 ) to "simultaneously press" 2 keyboard keys as a hotkey. The pykeyboard package comes installed with the PyUserInput installation.
Code Example : If I want to automatically have my program hit the hotkey combination ( CTRL + P ) to print something without me laying a finger on the keyboard, here is how I would do it through pykeyboard.
I begin by creating my keyboard object as shown above.
That should bring up the print window and I could have it continue forward to print on the default setting by having my script hit the Enter Key.
I can even have my script type custom strings. This can be useful if I want to save a file by a specified string in an automated form. I'll begin with the ( CTRL + S ) hotkey combination.
The "Save-As" window should pop up, prompting me to specify the filename that I want to have saved. So I'll pass that as a string.
Voila!