diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /tools/EventClients/examples | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/EventClients/examples')
13 files changed, 813 insertions, 0 deletions
diff --git a/tools/EventClients/examples/c#/XBMCDemoClient1.cs b/tools/EventClients/examples/c#/XBMCDemoClient1.cs new file mode 100644 index 0000000..df74dea --- /dev/null +++ b/tools/EventClients/examples/c#/XBMCDemoClient1.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows.Forms; +using XBMC; + +namespace XBMCEventClientDemo +{ + static class Program + { + /// <summary> + /// The main entry point for the application. + /// </summary> + [STAThread] + static void Main() + { + EventClient eventClient = new EventClient(); + eventClient.Connect("127.0.0.1", 9777); + + string iconFile = @"../../icons/icon.png"; + IconType iconType = IconType.ICON_PNG; + + if !File.Exists(iconFile) { + iconFile = @"/usr/share/xbmc/media/icon.png"; + if !File.Exists(iconFile) { + iconType = IconType.ICON_NONE; + } + } + + eventClient.SendHelo("XBMC Client Demo", iconType, iconFile); + System.Threading.Thread.Sleep(1000); + eventClient.SendNotification("XBMC Client Demo", "Notification Message", iconType, iconFile); + System.Threading.Thread.Sleep(1000); + eventClient.SendButton("dpadup", "XG", ButtonFlagsType.BTN_DOWN | ButtonFlagsType.BTN_NO_REPEAT, 0); + System.Threading.Thread.Sleep(1000); + eventClient.SendPing(); + System.Threading.Thread.Sleep(1000); + eventClient.SendMouse(32768, 32768); + System.Threading.Thread.Sleep(1000); + eventClient.SendLog(LogTypeEnum.LOGERROR, "Example error log message from XBMC Client Demo"); + System.Threading.Thread.Sleep(1000); + eventClient.SendAction("Mute"); + System.Threading.Thread.Sleep(1000); + eventClient.SendBye(); + } + } +} diff --git a/tools/EventClients/examples/c++/example_button1.cpp b/tools/EventClients/examples/c++/example_button1.cpp new file mode 100644 index 0000000..d96f268 --- /dev/null +++ b/tools/EventClients/examples/c++/example_button1.cpp @@ -0,0 +1,65 @@ +#include "../../lib/c++/xbmcclient.h" +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#ifdef _WIN32 +#include <Windows.h> // for sleep +#else +#include <unistd.h> +#endif + +int main(int argc, char **argv) +{ + /* connect to localhost, port 9777 using a UDP socket + this only needs to be done once. + by default this is where XBMC will be listening for incoming + connections. */ + CAddress my_addr; // Address => localhost on 9777 + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + printf("Error creating socket\n"); + return -1; + } + + my_addr.Bind(sockfd); + + std::string sIconFile = "../../icons/bluetooth.png"; + unsigned short usIconType = ICON_PNG; + + std::ifstream file (sIconFile, std::ios::in|std::ios::binary|std::ios::ate); + if (!file.is_open()) + { + sIconFile = "/usr/share/pixmaps/kodi/bluetooth.png"; + file.open(sIconFile, std::ios::in|std::ios::binary|std::ios::ate); + + if (!file.is_open()) { + usIconType = ICON_NONE; + } + else + { + file.close(); + } + } + else + { + file.close(); + } + + CPacketHELO HeloPackage("Example Remote", usIconType, sIconFile.c_str()); + HeloPackage.Send(sockfd, my_addr); + + sleep(5); + // press 'S' + CPacketBUTTON btn1('S', true); + btn1.Send(sockfd, my_addr); + + sleep(2); + // press the enter key (13 = enter) + CPacketBUTTON btn2(13, true); + btn2.Send(sockfd, my_addr); + + // BYE is not required since XBMC would have shut down + CPacketBYE bye; // CPacketPing if you want to ping + bye.Send(sockfd, my_addr); +} diff --git a/tools/EventClients/examples/c++/example_button2.cpp b/tools/EventClients/examples/c++/example_button2.cpp new file mode 100644 index 0000000..ddb55be --- /dev/null +++ b/tools/EventClients/examples/c++/example_button2.cpp @@ -0,0 +1,75 @@ +#include "../../lib/c++/xbmcclient.h" +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#ifdef _WIN32 +#include <Windows.h> // for sleep +#else +#include <unistd.h> +#endif + +int main(int argc, char **argv) +{ + /* connect to localhost, port 9777 using a UDP socket + this only needs to be done once. + by default this is where XBMC will be listening for incoming + connections. */ + CAddress my_addr; // Address => localhost on 9777 + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + printf("Error creating socket\n"); + return -1; + } + + my_addr.Bind(sockfd); + + std::string sIconFile = "../../icons/bluetooth.png"; + unsigned short usIconType = ICON_PNG; + + std::ifstream file (sIconFile, std::ios::in|std::ios::binary|std::ios::ate); + if (!file.is_open()) + { + sIconFile = "/usr/share/pixmaps/kodi/bluetooth.png"; + file.open(sIconFile, std::ios::in|std::ios::binary|std::ios::ate); + + if (!file.is_open()) { + usIconType = ICON_NONE; + } + else + { + file.close(); + } + } + else + { + file.close(); + } + + CPacketHELO HeloPackage("Example Remote", usIconType, sIconFile.c_str()); + HeloPackage.Send(sockfd, my_addr); + + sleep(5); + // Note that we have foo(BUTTON, DEVICEMAP); + CPacketBUTTON btn1("dpadup", "XG", 0); + btn1.Send(sockfd, my_addr); + + sleep(5); + + CPacketBUTTON btn2(0x28, 0); + btn2.Send(sockfd, my_addr); + + sleep(5); + + CPacketBUTTON btn3("right", "KB", 0); + btn3.Send(sockfd, my_addr); + + sleep(5); + // Release button + CPacketBUTTON btn4; + btn4.Send(sockfd, my_addr); + + // BYE is not required since XBMC would have shut down + CPacketBYE bye; // CPacketPing if you want to ping + bye.Send(sockfd, my_addr); +} diff --git a/tools/EventClients/examples/c++/example_log.cpp b/tools/EventClients/examples/c++/example_log.cpp new file mode 100644 index 0000000..ca61cb0 --- /dev/null +++ b/tools/EventClients/examples/c++/example_log.cpp @@ -0,0 +1,39 @@ +#include "../../lib/c++/xbmcclient.h" +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#ifdef _WIN32 +#include <Windows.h> // for sleep +#else +#include <unistd.h> +#endif + +int main(int argc, char **argv) +{ + /* connect to localhost, port 9777 using a UDP socket + this only needs to be done once. + by default this is where XBMC will be listening for incoming + connections. */ + + CAddress my_addr; // Address => localhost on 9777 + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + printf("Error creating socket\n"); + return -1; + } + + my_addr.Bind(sockfd); + //Normally this is already done by the client + CPacketHELO HeloPackage("LOG Test", ICON_NONE); + HeloPackage.Send(sockfd, my_addr); + + sleep(5); + //This works as XBMC internal CLog::LOG(LOGTYPE, STRING); + CPacketLOG packet(LOGERROR, "The Log Message"); + packet.Send(sockfd, my_addr); + + // BYE is not required since XBMC would have shut down + CPacketBYE bye; // CPacketPing if you want to ping + bye.Send(sockfd, my_addr); +} diff --git a/tools/EventClients/examples/c++/example_mouse.cpp b/tools/EventClients/examples/c++/example_mouse.cpp new file mode 100644 index 0000000..a0c5832 --- /dev/null +++ b/tools/EventClients/examples/c++/example_mouse.cpp @@ -0,0 +1,63 @@ +#include "../../lib/c++/xbmcclient.h" +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#ifdef _WIN32 +#include <Windows.h> // for sleep +#else +#include <unistd.h> +#endif + +int main(int argc, char **argv) +{ + /* connect to localhost, port 9777 using a UDP socket + this only needs to be done once. + by default this is where XBMC will be listening for incoming + connections. */ + CAddress my_addr; // Address => localhost on 9777 + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + printf("Error creating socket\n"); + return -1; + } + + my_addr.Bind(sockfd); + + std::string sIconFile = "../../icons/mouse.png"; + unsigned short usIconType = ICON_PNG; + + std::ifstream file (sIconFile, std::ios::in|std::ios::binary|std::ios::ate); + if (!file.is_open()) + { + sIconFile = "/usr/share/pixmaps/kodi/mouse.png"; + file.open(sIconFile, std::ios::in|std::ios::binary|std::ios::ate); + + if (!file.is_open()) { + usIconType = ICON_NONE; + } + else + { + file.close(); + } + } + else + { + file.close(); + } + + CPacketHELO HeloPackage("Example Mouse", usIconType, sIconFile.c_str()); + HeloPackage.Send(sockfd, my_addr); + + sleep(5); + + for(int i = 0; i < 65536; i++) + { + CPacketMOUSE mouse(i,i); + mouse.Send(sockfd, my_addr); + } + + // BYE is not required since XBMC would have shut down + CPacketBYE bye; // CPacketPing if you want to ping + bye.Send(sockfd, my_addr); +} diff --git a/tools/EventClients/examples/c++/example_notification.cpp b/tools/EventClients/examples/c++/example_notification.cpp new file mode 100644 index 0000000..5cd0657 --- /dev/null +++ b/tools/EventClients/examples/c++/example_notification.cpp @@ -0,0 +1,64 @@ +#include "../../lib/c++/xbmcclient.h" +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#ifdef _WIN32 +#include <Windows.h> // for sleep +#else +#include <unistd.h> +#endif + +int main(int argc, char **argv) +{ + /* connect to localhost, port 9777 using a UDP socket + this only needs to be done once. + by default this is where XBMC will be listening for incoming + connections. */ + + CAddress my_addr; // Address => localhost on 9777 + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + printf("Error creating socket\n"); + return -1; + } + + my_addr.Bind(sockfd); + + std::string sIconFile = "../../icons/mail.png"; + unsigned short usIconType = ICON_PNG; + + std::ifstream file (sIconFile, std::ios::in|std::ios::binary|std::ios::ate); + if (!file.is_open()) + { + sIconFile = "/usr/share/pixmaps/kodi/mail.png"; + file.open(sIconFile, std::ios::in|std::ios::binary|std::ios::ate); + + if (!file.is_open()) { + usIconType = ICON_NONE; + } + else + { + file.close(); + } + } + else + { + file.close(); + } + + CPacketHELO HeloPackage("Email Notifier", ICON_NONE); + HeloPackage.Send(sockfd, my_addr); + + sleep(5); + + CPacketNOTIFICATION packet("New Mail!", // caption + "RE: Check this out", // message + usIconType, // optional icon type + sIconFile.c_str()); // icon file (local) + packet.Send(sockfd, my_addr); + + // BYE is not required since XBMC would have shut down + CPacketBYE bye; // CPacketPing if you want to ping + bye.Send(sockfd, my_addr); +} diff --git a/tools/EventClients/examples/java/XBMCDemoClient1.java b/tools/EventClients/examples/java/XBMCDemoClient1.java new file mode 100644 index 0000000..5bb2821 --- /dev/null +++ b/tools/EventClients/examples/java/XBMCDemoClient1.java @@ -0,0 +1,70 @@ +package org.xbmc.eventclient.demo; + +import java.io.File; +import java.io.IOException; +import java.net.Inet4Address; +import java.net.InetAddress; + +import org.xbmc.eventclient.XBMCClient; + +/** + * Simple Demo EventClient + * @author Stefan Agner + * + */ +public class XBMCDemoClient1 { + + /** + * Simple Demo EventClient + * @param args + */ + public static void main(String[] args) throws IOException, InterruptedException { + InetAddress host = Inet4Address.getByAddress(new byte[] { (byte)127, 0, 0, 1 } ); + + Thread.sleep(20000); + + String iconFile = "/usr/share/xbmc/media/icon.png"; + + if (! new File(iconFile).exists()) { + iconFile = "../../icons/icon.png"; + + if (! new File(iconFile).exists()) { + iconFile = ""; + } + } + + XBMCClient oXBMCClient = null; + + if (iconFile != "") { + oXBMCClient = new XBMCClient(host, 9777, "My Client", iconFile); + } else { + oXBMCClient = new XBMCClient(host, 9777, "My Client"); + } + + Thread.sleep(7000); + + oXBMCClient.sendNotification("My Title", "My Message"); + + + Thread.sleep(7000); + + oXBMCClient.sendButton("KB", "escape", false, true, false, (short)0 , (byte)0); + + + Thread.sleep(7000); + oXBMCClient.sendButton("KB", "escape", true, true, false, (short)0 , (byte)0); + oXBMCClient.sendNotification("My Title", "Escape sent"); + + Thread.sleep(1000); + + oXBMCClient.sendButton("KB", "escape", true, false, false, (short)0 , (byte)0); + oXBMCClient.sendNotification("My Title", "Escape released"); + + Thread.sleep(7000); + oXBMCClient.sendLog((byte)0, "My Client disconnects...."); + oXBMCClient.sendNotification("My Title", "Client will disconnect"); + oXBMCClient.stopClient(); + + } + +} diff --git a/tools/EventClients/examples/python/example_action.py b/tools/EventClients/examples/python/example_action.py new file mode 100755 index 0000000..b87fc29 --- /dev/null +++ b/tools/EventClients/examples/python/example_action.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +# This is a simple example showing how you can send a key press event +# to XBMC using the XBMCClient class + +import os +from socket import * +import sys + +if os.path.exists("../../lib/python"): + # try loading modules from source directory + sys.path.append("../../lib/python") + + from xbmcclient import * + + ICON_PATH = "../../icons/" +else: + # fallback to system wide modules + + from kodi.xbmcclient import * + from kodi.defs import * + +def main(): + + host = "localhost" + port = 9777 + + # Create an XBMCClient object and connect + xbmc = XBMCClient("Example Remote", ICON_PATH + "/bluetooth.png") + xbmc.connect() + + # send a up key press using the xbox gamepad map "XG" and button + # name "dpadup" ( see PacketBUTTON doc for more details) + try: + xbmc.send_action(sys.argv[2], ACTION_BUTTON) + except: + try: + xbmc.send_action(sys.argv[1], ACTION_EXECBUILTIN) + except Exception as e: + print(str(e)) + xbmc.send_action("ActivateWindow(ShutdownMenu)") + + + # ok we're done, close the connection + # Note that closing the connection clears any repeat key that is + # active. So in this example, the actual release button event above + # need not have been sent. + xbmc.close() + +if __name__=="__main__": + main() diff --git a/tools/EventClients/examples/python/example_button1.py b/tools/EventClients/examples/python/example_button1.py new file mode 100755 index 0000000..abdfe49 --- /dev/null +++ b/tools/EventClients/examples/python/example_button1.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 + +# This is a simple example showing how you can send 2 button events +# to XBMC in a queued fashion to shut it down. + +# Queued button events are not repeatable. + +# The basic idea is to create single packets and shoot them to XBMC +# The provided library implements some of the support commands and +# takes care of creating the actual packet. Using it is as simple +# as creating an object with the required constructor arguments and +# sending it through a socket. + +# Currently, only keyboard keys are supported so the key codes used +# below are the same key codes used in guilib/common/SDLKeyboard.cpp + +# In effect, anything that can be done with the keyboard can be done +# using the event client. + +# import the XBMC client library +# NOTE: The library is not complete yet but is usable at this stage. + +import os +from socket import * +import sys + +if os.path.exists("../../lib/python"): + # try loading modules from source directory + sys.path.append("../../lib/python") + + from xbmcclient import * + + ICON_PATH = "../../icons/" +else: + # fallback to system wide modules + + from kodi.xbmcclient import * + from kodi.defs import * + +def main(): + import time + import sys + + # connect to localhost, port 9777 using a UDP socket + # this only needs to be done once. + # by default this is where XBMC will be listening for incoming + # connections. + host = "localhost" + port = 9777 + addr = (host, port) + sock = socket(AF_INET,SOCK_DGRAM) + + # First packet must be HELO (no it's not a typo) and can contain an icon + # 'icon_type' can be one of ICON_NONE, ICON_PNG, ICON_JPG or ICON_GIF + packet = PacketHELO(devicename="Example Remote", + icon_type=ICON_PNG, + icon_file=ICON_PATH + "/bluetooth.png") + packet.send(sock, addr) + + # IMPORTANT: After a HELO packet is sent, the client needs to "ping" XBMC + # at least once every 60 seconds or else the client will time out. + # Every valid packet sent to XBMC acts as a ping, however if no valid + # packets NEED to be sent (eg. the user hasn't pressed a key in 50 seconds) + # then you can use the PacketPING class to send a ping packet (which is + # basically just an empty packet). See below. + + # Once a client times out, it will need to reissue the HELO packet. + # Currently, since this is a unidirectional protocol, there is no way + # for the client to know if it has timed out. + + # wait for notification window to close (in XBMC) + time.sleep(5) + + # press 'S' + packet = PacketBUTTON(code='S', queue=1) + packet.send(sock, addr) + + # wait for a few seconds + time.sleep(2) + + # press the enter key (13 = enter) + packet = PacketBUTTON(code=13, queue=1) + packet.send(sock, addr) + + # BYE is not required since XBMC would have shut down + packet = PacketBYE() # PacketPING if you want to ping + packet.send(sock, addr) + +if __name__=="__main__": + main() diff --git a/tools/EventClients/examples/python/example_button2.py b/tools/EventClients/examples/python/example_button2.py new file mode 100755 index 0000000..bb91704 --- /dev/null +++ b/tools/EventClients/examples/python/example_button2.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 + +# This is a simple example showing how you can send a key press event +# to XBMC in a non-queued fashion to achieve a button pressed down +# event i.e. a key press that repeats. + +# The repeat interval is currently hard coded in XBMC but that might +# change in the future. + +# NOTE: Read the comments in 'example_button1.py' for a more detailed +# explanation. + +import os +from socket import * +import sys + +if os.path.exists("../../lib/python"): + # try loading modules from source directory + sys.path.append("../../lib/python") + + from xbmcclient import * + + ICON_PATH = "../../icons/" +else: + # fallback to system wide modules + + from kodi.xbmcclient import * + from kodi.defs import * + +def main(): + import time + import sys + + host = "localhost" + port = 9777 + addr = (host, port) + + sock = socket(AF_INET,SOCK_DGRAM) + + # First packet must be HELO and can contain an icon + packet = PacketHELO("Example Remote", ICON_PNG, + ICON_PATH + "/bluetooth.png") + packet.send(sock, addr) + + # wait for notification window to close (in XBMC) + time.sleep(5) + + # send a up key press using the xbox gamepad map "XG" and button + # name "dpadup" ( see PacketBUTTON doc for more details) + packet = PacketBUTTON(map_name="XG", button_name="dpadup") + packet.send(sock, addr) + + # wait for a few seconds to see its effect + time.sleep(5) + + # send a down key press using the raw keyboard code + packet = PacketBUTTON(code=0x28) + packet.send(sock, addr) + + # wait for a few seconds to see its effect + time.sleep(5) + + # send a right key press using the keyboard map "KB" and button + # name "right" + packet = PacketBUTTON(map_name="KB", button_name="right") + packet.send(sock, addr) + + # wait for a few seconds to see its effect + time.sleep(5) + + # that's enough, release the button. During release, button code + # doesn't matter. + packet = PacketBUTTON(code=0x28, down=0) + packet.send(sock, addr) + + # ok we're done, close the connection + # Note that closing the connection clears any repeat key that is + # active. So in this example, the actual release button event above + # need not have been sent. + packet = PacketBYE() + packet.send(sock, addr) + +if __name__=="__main__": + main() diff --git a/tools/EventClients/examples/python/example_mouse.py b/tools/EventClients/examples/python/example_mouse.py new file mode 100755 index 0000000..7c43782 --- /dev/null +++ b/tools/EventClients/examples/python/example_mouse.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +# This is a simple example showing how you can send mouse movement +# events to XBMC. + +# NOTE: Read the comments in 'example_button1.py' for a more detailed +# explanation. + +import os +from socket import * +import sys + +if os.path.exists("../../lib/python"): + # try loading modules from source directory + sys.path.append("../../lib/python") + + from xbmcclient import * + + ICON_PATH = "../../icons/" +else: + # fallback to system wide modules + + from kodi.xbmcclient import * + from kodi.defs import * + +def main(): + import time + import sys + + host = "localhost" + port = 9777 + addr = (host, port) + + sock = socket(AF_INET,SOCK_DGRAM) + + # First packet must be HELO and can contain an icon + packet = PacketHELO("Example Mouse", ICON_PNG, + ICON_PATH + "/mouse.png") + packet.send(sock, addr) + + # wait for notification window to close (in XBMC) + time.sleep(2) + + # send mouse events to take cursor from top left to bottom right of the screen + # here 0 to 65535 will map to XBMC's screen width and height. + # Specifying absolute mouse coordinates is unsupported currently. + for i in range(0, 65535, 2): + packet = PacketMOUSE(i,i) + packet.send(sock, addr) + + # ok we're done, close the connection + packet = PacketBYE() + packet.send(sock, addr) + +if __name__=="__main__": + main() diff --git a/tools/EventClients/examples/python/example_notification.py b/tools/EventClients/examples/python/example_notification.py new file mode 100755 index 0000000..fd1a82e --- /dev/null +++ b/tools/EventClients/examples/python/example_notification.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +# This is a simple example showing how you can show a notification +# window with a custom icon inside XBMC. It could be used by mail +# monitoring apps, calendar apps, etc. + +import os +from socket import * +import sys + +if os.path.exists("../../lib/python"): + # try loading modules from source directory + sys.path.append("../../lib/python") + + from xbmcclient import * + + ICON_PATH = "../../icons/" +else: + # fallback to system wide modules + + from kodi.xbmcclient import * + from kodi.defs import * + +def main(): + import time + import sys + + host = "localhost" + port = 9777 + addr = (host, port) + sock = socket(AF_INET,SOCK_DGRAM) + + packet = PacketHELO("Email Notifier", ICON_NONE) + packet.send(sock, addr) + + # wait for 5 seconds + time.sleep (5) + + packet = PacketNOTIFICATION("New Mail!", # caption + "RE: Check this out", # message + ICON_PNG, # optional icon type + ICON_PATH + "/mail.png") # icon file (local) + packet.send(sock, addr) + + packet = PacketBYE() + packet.send(sock, addr) + +if __name__=="__main__": + main() diff --git a/tools/EventClients/examples/python/example_simple.py b/tools/EventClients/examples/python/example_simple.py new file mode 100755 index 0000000..2d807e8 --- /dev/null +++ b/tools/EventClients/examples/python/example_simple.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +# This is a simple example showing how you can send a key press event +# to XBMC using the XBMCClient class + +import os +from socket import * +import sys +import time + +if os.path.exists("../../lib/python"): + # try loading modules from source directory + sys.path.append("../../lib/python") + + from xbmcclient import * + + ICON_PATH = "../../icons/" +else: + # fallback to system wide modules + + from kodi.xbmcclient import * + from kodi.defs import * + +def main(): + + host = "localhost" + port = 9777 + + # Create an XBMCClient object and connect + xbmc = XBMCClient("Example Remote", ICON_PATH + "/bluetooth.png") + xbmc.connect() + + # wait for notification window to close (in XBMC) (optional) + time.sleep(5) + + # send a up key press using the xbox gamepad map "XG" and button + # name "dpadup" ( see PacketBUTTON doc for more details) + xbmc.send_button(map="XG", button="dpadup") + + # wait for a few seconds to see its effect + time.sleep(5) + + # send a right key press using the keyboard map "KB" and button + # name "right" + xbmc.send_keyboard_button("right") + + # wait for a few seconds to see its effect + time.sleep(5) + + # that's enough, release the button. + xbmc.release_button() + + # ok we're done, close the connection + # Note that closing the connection clears any repeat key that is + # active. So in this example, the actual release button event above + # need not have been sent. + xbmc.close() + +if __name__=="__main__": + main() |