22 lines
597 B
Python
22 lines
597 B
Python
|
import string
|
||
|
class keyboard:
|
||
|
def __init__(self, canvas):
|
||
|
tkeys = list(string.ascii_letters)
|
||
|
self._keys = {}
|
||
|
for i in tkeys:
|
||
|
self._keys[i] = False
|
||
|
canvas.bind("<KeyPress>", self.keypupd)
|
||
|
canvas.bind("<KeyRelease>", self.keydupd)
|
||
|
|
||
|
def keypupd(self, event):
|
||
|
event = event.char
|
||
|
if event in self._keys:
|
||
|
self._keys[event] = True
|
||
|
|
||
|
def keydupd(self, event):
|
||
|
event = event.char
|
||
|
if event in self._keys:
|
||
|
self._keys[event] = False
|
||
|
|
||
|
def getkeys(self):
|
||
|
return self._keys
|