[IronPython] How to get Keyboard Input

Andrew Evans evans.d.andrew at gmail.com
Thu Aug 5 23:54:24 CEST 2010


Hello I am trying to use the up down left right arrow keys to move an object

How ever it does not seem to work and I receive no error messages any ideas?

from System.Windows.Input import KeyEventHandler

velocity = 10

class Gui():
    def __init__(self):
        KeyEventHandler(self.KeyDown_Control)
................................


    def KeyDown_Control(self, s, e):
        if e.Key == Key.Right:
            self.canvas.SetLeft(self.ship, self.canvas.GetLeft(self.ship) +
velocity)
        elif e.Key == Key.Left:
            self.canvas.SetLeft(self.ship, self.canvas.GetLeft(self.ship) -
velocity)
        elif e.Key == Key.Up:
            self.canvas.SetTop(self.ship, self.canvas.GetTop(self.ship) -
velocity)
        elif e.Key == Key.Down:
            self.canvas.SetTop(self.ship, self.canvas.GetTop(self.ship) +
velocity)

Cheers

and thank you

Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100805/6829d9b2/attachment.html>


More information about the Ironpython-users mailing list