[Subtitles] Partial fix for text/border color gap
[xbmc.git] / tools / EventClients / examples / python / example_button2.py
blobbb91704d063b35f6addc1e82670cd9d8795d6229
1 #!/usr/bin/env python3
3 # This is a simple example showing how you can send a key press event
4 # to XBMC in a non-queued fashion to achieve a button pressed down
5 # event i.e. a key press that repeats.
7 # The repeat interval is currently hard coded in XBMC but that might
8 # change in the future.
10 # NOTE: Read the comments in 'example_button1.py' for a more detailed
11 # explanation.
13 import os
14 from socket import *
15 import sys
17 if os.path.exists("../../lib/python"):
18 # try loading modules from source directory
19 sys.path.append("../../lib/python")
21 from xbmcclient import *
23 ICON_PATH = "../../icons/"
24 else:
25 # fallback to system wide modules
27 from kodi.xbmcclient import *
28 from kodi.defs import *
30 def main():
31 import time
32 import sys
34 host = "localhost"
35 port = 9777
36 addr = (host, port)
38 sock = socket(AF_INET,SOCK_DGRAM)
40 # First packet must be HELO and can contain an icon
41 packet = PacketHELO("Example Remote", ICON_PNG,
42 ICON_PATH + "/bluetooth.png")
43 packet.send(sock, addr)
45 # wait for notification window to close (in XBMC)
46 time.sleep(5)
48 # send a up key press using the xbox gamepad map "XG" and button
49 # name "dpadup" ( see PacketBUTTON doc for more details)
50 packet = PacketBUTTON(map_name="XG", button_name="dpadup")
51 packet.send(sock, addr)
53 # wait for a few seconds to see its effect
54 time.sleep(5)
56 # send a down key press using the raw keyboard code
57 packet = PacketBUTTON(code=0x28)
58 packet.send(sock, addr)
60 # wait for a few seconds to see its effect
61 time.sleep(5)
63 # send a right key press using the keyboard map "KB" and button
64 # name "right"
65 packet = PacketBUTTON(map_name="KB", button_name="right")
66 packet.send(sock, addr)
68 # wait for a few seconds to see its effect
69 time.sleep(5)
71 # that's enough, release the button. During release, button code
72 # doesn't matter.
73 packet = PacketBUTTON(code=0x28, down=0)
74 packet.send(sock, addr)
76 # ok we're done, close the connection
77 # Note that closing the connection clears any repeat key that is
78 # active. So in this example, the actual release button event above
79 # need not have been sent.
80 packet = PacketBYE()
81 packet.send(sock, addr)
83 if __name__=="__main__":
84 main()