source: xplra/test/hotkeytest.py@ 53:84a550d370b1

Last change on this file since 53:84a550d370b1 was 53:84a550d370b1, checked in by István Váradi <ivaradi@…>, 11 years ago

Added test program for the hotkey handling

File size: 1.4 KB
Line 
1# Test program for the Python client library: hotkey handling
2
3#------------------------------------------------------------------------------
4
5import time
6
7#------------------------------------------------------------------------------
8
9if __name__ == "__main__":
10 from xplra import XPlane, ProtocolException
11
12 xplane = XPlane()
13
14 try:
15 print "Connecting to X-Plane..."
16 xplane.connect()
17 print "Connected to X-Plane."
18 print
19
20 print "Registering hotkeys: Ctrl+A, Shift+B, Ctrl+Shift+C, Ctrl+Q..."
21 xplane.registerHotkeys([0x0241, 0x0142, 0x0343, 0x0251])
22 print "Registered hotkeys..."
23
24 print "Listening to hotkeys..."
25 while True:
26 states = xplane.queryHotkeys()
27 message = ""
28 if states[3]: break
29 if states[0]:
30 if message: message += ", "
31 message += "Ctrl+A"
32 if states[1]:
33 if message: message += ", "
34 message += "Shift+B"
35 if states[2]:
36 if message: message += ", "
37 message += "Ctrl+Shift+C"
38 if message:
39 message += " pressed"
40 xplane.showMessage(message, 3.0)
41
42 time.sleep(0.5)
43
44 except Exception as e:
45 print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e)
46 finally:
47 xplane.disconnect()
Note: See TracBrowser for help on using the repository browser.