[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [libvirt-java] [PATCH 57/65] Implement Domain.sendKey



This wraps the virDomainSendKey libvirt function available since version
0.9.3.

Signed-off-by: Claudio Bley <cbley av-test de>
---
 src/main/java/org/libvirt/Domain.java      |   12 ++++++++
 src/main/java/org/libvirt/KeycodeSet.java  |   46 ++++++++++++++++++++++++++++
 src/main/java/org/libvirt/jna/Libvirt.java |    1 +
 3 files changed, 59 insertions(+)
 create mode 100644 src/main/java/org/libvirt/KeycodeSet.java

diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java
index e0dba46..1c0af91 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -1352,6 +1352,18 @@ public class Domain {
     }
 
     /**
+     * Send key(s) to the guest.
+     *
+     * @param  codeset  the set of keycodes
+     * @param  holdtime the duration that the keys will be held (in milliseconds)
+     * @param  keys     the key codes to be send
+     */
+    public void sendKey(KeycodeSet codeset, int holdtime, int... keys) throws LibvirtException {
+        processError(libvirt.virDomainSendKey(this.VDP, codeset.ordinal(),
+                                              holdtime, keys, keys.length, 0));
+    }
+
+    /**
      * Shuts down this domain, the domain object is still usable there after but
      * the domain OS is being stopped. Note that the guest OS may ignore the
      * request. TODO: should we add an option for reboot, knowing it may not be
diff --git a/src/main/java/org/libvirt/KeycodeSet.java b/src/main/java/org/libvirt/KeycodeSet.java
new file mode 100644
index 0000000..132e508
--- /dev/null
+++ b/src/main/java/org/libvirt/KeycodeSet.java
@@ -0,0 +1,46 @@
+package org.libvirt;
+
+/**
+ */
+public enum KeycodeSet {
+    /**
+     * Linux key code set.
+     * <p>
+     * Defined in the linux/input.h header, this set of key codes is able
+     * to represent any scan code from any type of keyboard.
+     */
+    LINUX,
+
+    /** IBM XT keyboard code set */
+    XT,
+
+    /** AT set 1 key codes */
+    ATSET1,
+
+    /** AT set 2 key codes */
+    ATSET2,
+
+    /** AT set 3 key codes */
+    ATSET3,
+
+    /** Apple OS-X virtual key codes */
+    OSX,
+
+    /** */
+    XT_KBD,
+
+    /** Key code set as defined by the USB HID specification */
+    USB,
+
+    /**
+     * Microsoft Windows virtual key code set
+     * <p>
+     * Reference: <a target='blank'
+     *  href='http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx'
+     * >MSDN Virtual-Key Codes</a>.
+     */
+    WIN32,
+
+    /** Key code set as used by GTK-VNC and QEMU */
+    RFB;
+}
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java
index a6d3b1d..c8735d2 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -304,6 +304,7 @@ public interface Libvirt extends Library {
     int virDomainRevertToSnapshot(DomainSnapshotPointer virDomainSnapshotPtr, int flags);
     int virDomainResume(DomainPointer virDomainPtr);
     int virDomainSave(DomainPointer virDomainPtr, String to);
+    int virDomainSendKey(DomainPointer virDomainPtr, int codeset, int holdtime, int[] keycodes, int nkeycodes, int flags);
     int virDomainSetAutostart(DomainPointer virDomainPtr, int autoStart);
     int virDomainSetMaxMemory(DomainPointer virDomainPtr, NativeLong maxMemory);
     int virDomainSetMemory(DomainPointer virDomainPtr, NativeLong maxMemory);
-- 
1.7.9.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]