From 336f6f873c52ef62e2f304436b381c166eac872f Mon Sep 17 00:00:00 2001 From: troido Date: Mon, 13 Nov 2017 11:57:00 +0100 Subject: used curses.keyname instead of ord. It is now possible to use non printable keys for controlling (like arrow keys) --- asciifarm/client/gameclient.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'asciifarm/client') diff --git a/asciifarm/client/gameclient.py b/asciifarm/client/gameclient.py index 6038fec..88238d1 100644 --- a/asciifarm/client/gameclient.py +++ b/asciifarm/client/gameclient.py @@ -27,12 +27,12 @@ class Client: for key, commands in keybindings["input"].items(): if isinstance(commands[0], str): commands = [commands] - self.commands[ord(key)] = [["input", command] for command in commands] + self.commands[key] = [["input", command] for command in commands] self.controlsString = "Controls:\n"+'\n'.join( - chr(key) + ": " + ', '.join(' '.join(action[1]) for action in actions) + key + ": " + ', '.join(' '.join(action[1]) for action in actions) for key, actions in self.commands.items() - if chr(key) in string.printable) + if key in string.printable) self.display.showInfo(self.controlsString) @@ -96,10 +96,6 @@ class Client: self.display.setGround(msg[1]) if msgType == "message": self.log(msg[1]) - #self.display.addMessage(msg[1]) - #if self.logFile: - #with(open(self.logFile, 'a')) as f: - #f.write(msg[1]+'\n') self.display.update() @@ -115,8 +111,10 @@ class Client: key = self.stdscr.getch() if key == 27: self.keepalive = False - if key in self.commands: - self.connection.send(json.dumps(self.commands[key])) + return + keyname = str(curses.keyname(key), "utf-8") + if keyname in self.commands: + self.connection.send(json.dumps(self.commands[keyname])) -- cgit