Python (3.6.1) detection and tooltips

I'm new to Python and I tried to print the key when clicking on windows and show the key in the popup message:

import msvcrt
import ctypes  # An included library with Python install.

def Mbox(title, text, style):
    ctypes.windll.user32.MessageBoxW(0, text, title, style)

while True:
    if msvcrt.kbhit()== True:
        key = msvcrt.getch()
        print(key)  # just to show the result
        Mbox(key, key, 1)

      

And the problems are as follows:

1) The output if I press a key is different, for example: " A " is " b'A ' " Why? and how can I change it to " A "? (the output in the popup looks even weirder: 1X when I press 1 or 2 * x when I press 2)

2) While True:

makes the code run constantly and that way it keeps detecting if a key was pressed?

3) Is there a library for python that detects key presses for windows and Linux in general?

+3


source to share


1 answer


Ok, I found some answers:

1) msvcrt.getwch()

A wide char variant of getch () that returns a Unicode value.

More details: https://docs.python.org/3.6/library/msvcrt.html



2) I think yes, if someone can confirm that they are happy.

3) Don't know what I know, there are different libs for each op system (again, if wrong, leave a note here).

0


source







All Articles