dirtywords

portable text interface framework  https://pypi.python.org/pypi/dirtywords
git clone https://git.ce9e.org/dirtywords.git

commit
25e19f6ee53fce5cdd9746a292df1613b1ee3c59
parent
33e932039e43c26ea0380404acb903d87c935c65
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2015-03-22 19:19
example: enable arrow keys

Diffstat

M example.py 9 +++++----

1 files changed, 5 insertions, 4 deletions


diff --git a/example.py b/example.py

@@ -2,6 +2,7 @@ import sys
    2     2 from time import sleep
    3     3 
    4     4 from dirtywords import Screen, AttrString
   -1     5 from dirtywords.constants import KEYS
    5     6 
    6     7 
    7     8 class Player(object):
@@ -41,13 +42,13 @@ if __name__ == '__main__':
   41    42         while 1:
   42    43             for event in scr.get_key_events():
   43    44                 if event['type'] == 'keydown':
   44    -1                     if event['key'] == ord('h'):
   -1    45                     if event['key'] in [ord('h'), KEYS['Left']]:
   45    46                         player.direction = 'left'
   46    -1                     elif event['key'] == ord('j'):
   -1    47                     elif event['key'] in [ord('j'), KEYS['Down']]:
   47    48                         player.direction = 'down'
   48    -1                     elif event['key'] == ord('k'):
   -1    49                     elif event['key'] in [ord('k'), KEYS['Up']]:
   49    50                         player.direction = 'up'
   50    -1                     elif event['key'] == ord('l'):
   -1    51                     elif event['key'] in [ord('l'), KEYS['Right']]:
   51    52                         player.direction = 'right'
   52    53                     elif event['key'] == ord('q'):
   53    54                         scr.cleanup()