How to capture events in Python?

0

I'd like to capture the user-clicked keys through IronPython. I understand a bit of C #, but I'm not understanding how I would do this in Python.

Code:

import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import KeyEventArgs, Form, Application, Button

class App(Form):
    def __init__(self):

        self.KeyUp = self.TeclaClicada #Não sei como faria, aqui está o erro.
        self.Text = "Capturar tecla"

    def TeclaClicada(self, key):
        print(key)

form = App()
Application.Run(form)
    
asked by anonymous 27.09.2018 / 03:29

1 answer

1
self.KeyUp += self.TeclaClicada

Or self.KeyDown or self.KeyPress ... depends on the key you want to capture, some go to one event, some to another ...

Your TeclaClicada function must have this signature:

def TeclaClicada(self, e, args):
    key = e.KeyChar
    if key == ...:
        ...
    
27.09.2018 / 17:51