How to capture events in Python?

Asked

Viewed 353 times

0

I would like to capture the user-clicked keys through Ironpython. I understand a little C#, but I don’t understand how I would do it 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)

1 answer

1


self.KeyUp += self.TeclaClicada

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

Its function TeclaClicada has to have that signature:

def TeclaClicada(self, e, args):
    key = e.KeyChar
    if key == ...:
        ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.