[gtk-vnc-devel] PATCH: Add a 'send keys' function
- From: "Daniel P. Berrange" <berrange redhat com>
- To: gtk-vnc-devel <gtk-vnc-devel lists sourceforge net>
- Subject: [gtk-vnc-devel] PATCH: Add a 'send keys' function
- Date: Tue, 17 Jul 2007 17:04:49 +0100
The attached patch
- Adds vnc_display_send_keys(VncDisplay *d, const guint *keys, int nkeys)
- A manually written python binding taking a list of strings, and convert
them to guint keyvals - PyGTK doesn't have a binding for GDK keysym
values & the auto-generator can't deal with guint * anyway.
- Extension to gvncviewer.c and gvncviewer.py adding 3 buttons for sending
Ctrl+Alt+F1, Ctrl+Alt+F7, Ctrl+Alt+Del to demonstrate use of the API
Regards,
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
diff -r ab919470c43f examples/gvncviewer.c
--- a/examples/gvncviewer.c Sun Jul 15 17:17:44 2007 -0400
+++ b/examples/gvncviewer.c Tue Jul 17 11:29:30 2007 -0400
@@ -1,5 +1,6 @@
#include "vncdisplay.h"
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
#include <stdlib.h>
#include <sys/socket.h>
@@ -22,10 +23,33 @@ void vnc_ungrab(GtkWidget *vnc)
gtk_window_set_title(GTK_WINDOW(window), "GVncViewer");
}
+void send_caf1(GtkWidget *button)
+{
+ gint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_F1 };
+ printf("Sending Ctrl+Alt+F1\n");
+ vnc_display_send_keys(VNC_DISPLAY(vnc), keys, sizeof(keys)/sizeof(keys[0]));
+}
+void send_caf7(GtkWidget *button)
+{
+ gint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_F7 };
+ printf("Sending Ctrl+Alt+F7\n");
+ vnc_display_send_keys(VNC_DISPLAY(vnc), keys, sizeof(keys)/sizeof(keys[0]));
+}
+void send_cad(GtkWidget *button)
+{
+ gint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_Delete };
+ printf("Sending Ctrl+Alt+Delete\n");
+ vnc_display_send_keys(VNC_DISPLAY(vnc), keys, sizeof(keys)/sizeof(keys[0]));
+}
int main(int argc, char **argv)
{
char *ret = NULL;
+ GtkWidget *layout;
+ GtkWidget *buttons;
+ GtkWidget *caf1;
+ GtkWidget *caf7;
+ GtkWidget *cad;
if (argc != 3 && argc != 4) {
fprintf(stderr, "syntax: vnc-test ipaddress port [password]\n");
@@ -36,8 +60,19 @@ int main(int argc, char **argv)
vnc = vnc_display_new();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "GVncViewer");
+ layout = gtk_vbox_new(FALSE, 3);
+ buttons = gtk_hbox_new(FALSE, 3);
+ caf1 = gtk_button_new_with_label("Ctrl+Alt+F1");
+ caf7 = gtk_button_new_with_label("Ctrl+Alt+F7");
+ cad = gtk_button_new_with_label("Ctrl+Alt+Del");
- gtk_container_add(GTK_CONTAINER(window), vnc);
+ gtk_container_add(GTK_CONTAINER(window), layout);
+ gtk_container_add(GTK_CONTAINER(layout), buttons);
+ gtk_container_add(GTK_CONTAINER(layout), vnc);
+ gtk_container_add(GTK_CONTAINER(buttons), caf1);
+ gtk_container_add(GTK_CONTAINER(buttons), caf7);
+ gtk_container_add(GTK_CONTAINER(buttons), cad);
gtk_widget_show_all(window);
if (argc == 4)
@@ -45,7 +80,7 @@ int main(int argc, char **argv)
vnc_display_open_name(VNC_DISPLAY(vnc), argv[1], argv[2]);
vnc_display_set_keyboard_grab(VNC_DISPLAY(vnc), TRUE);
vnc_display_set_pointer_grab(VNC_DISPLAY(vnc), TRUE);
- vnc_display_set_pointer_local(VNC_DISPLAY(vnc), TRUE);
+ //vnc_display_set_pointer_local(VNC_DISPLAY(vnc), TRUE);
gtk_signal_connect(GTK_OBJECT(window), "delete-event",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
@@ -54,6 +89,13 @@ int main(int argc, char **argv)
gtk_signal_connect(GTK_OBJECT(vnc), "vnc-pointer-ungrab",
GTK_SIGNAL_FUNC(vnc_ungrab), NULL);
+
+ gtk_signal_connect(GTK_OBJECT(caf1), "clicked",
+ GTK_SIGNAL_FUNC(send_caf1), NULL);
+ gtk_signal_connect(GTK_OBJECT(caf7), "clicked",
+ GTK_SIGNAL_FUNC(send_caf7), NULL);
+ gtk_signal_connect(GTK_OBJECT(cad), "clicked",
+ GTK_SIGNAL_FUNC(send_cad), NULL);
gtk_signal_connect(GTK_OBJECT(vnc), "vnc-disconnected",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
diff -r ab919470c43f examples/gvncviewer.py
--- a/examples/gvncviewer.py Sun Jul 15 17:17:44 2007 -0400
+++ b/examples/gvncviewer.py Tue Jul 17 11:52:30 2007 -0400
@@ -8,28 +8,56 @@ if len(sys.argv) != 3 and len(sys.argv)
print "syntax: gvncviewer.py host port [password]"
sys.exit(1)
-w = gtk.Window()
-v = gtkvnc.Display()
+window = gtk.Window()
+viewer = gtkvnc.Display()
def vnc_grab(src):
- w.set_title("Press Ctrl+Alt to release pointer. GVncViewer")
+ window.set_title("Press Ctrl+Alt to release pointer. GVncViewer")
def vnc_ungrab(src):
- w.set_title("GVncViewer")
+ window.set_title("GVncViewer")
+def send_caf1(src):
+ print "Send Ctrl+Alt+F1"
+ viewer.send_keys(["Control_L", "Alt_L", "F1"])
+def send_caf7(src):
+ print "Send Ctrl+Alt+F7"
+ viewer.send_keys(["Control_L", "Alt_L", "F7"])
+def send_cad(src):
+ print "Send Ctrl+Alt+Del"
+ print dir(viewer)
+ viewer.send_keys(["Control_L", "Alt_L", "Del"])
-w.add(v)
-w.show_all()
+layout = gtk.VBox()
+window.add(layout)
-v.set_pointer_grab(True)
-v.set_keyboard_grab(True)
+buttons = gtk.HBox()
+caf1 = gtk.Button("Ctrl+Alt+F1")
+caf7 = gtk.Button("Ctrl+Alt+F7")
+cad = gtk.Button("Ctrl+Alt+Del")
+buttons.add(caf1)
+buttons.add(caf7)
+buttons.add(cad)
+caf1.connect("clicked", send_caf1)
+caf7.connect("clicked", send_caf7)
+cad.connect("clicked", send_cad)
+
+
+layout.add(buttons)
+layout.add(viewer)
+
+window.show_all()
+
+viewer.set_pointer_grab(True)
+viewer.set_keyboard_grab(True)
#v.set_pointer_local(True)
if len(sys.argv) == 4:
- v.set_password(sys.argv[3])
-v.open_name(sys.argv[1], sys.argv[2])
-v.connect("vnc-pointer-grab", vnc_grab)
-v.connect("vnc-pointer-ungrab", vnc_ungrab)
-v.connect("vnc-disconnected", gtk.main_quit)
+ viewer.set_password(sys.argv[3])
+print "Connecting to %s %s" % (sys.argv[1], sys.argv[2])
+viewer.open_name(sys.argv[1], sys.argv[2])
+viewer.connect("vnc-pointer-grab", vnc_grab)
+viewer.connect("vnc-pointer-ungrab", vnc_ungrab)
+viewer.connect("vnc-disconnected", gtk.main_quit)
gtk.main()
diff -r ab919470c43f src/libgtk-vnc_sym.version
--- a/src/libgtk-vnc_sym.version Sun Jul 15 17:17:44 2007 -0400
+++ b/src/libgtk-vnc_sym.version Sun Jul 15 15:20:52 2007 -0400
@@ -4,6 +4,9 @@
vnc_display_new;
vnc_display_open_fd;
vnc_display_open_name;
+
+ vnc_display_send_keys;
+
vnc_display_set_password;
vnc_display_set_use_shm;
vnc_display_set_pointer_local;
diff -r ab919470c43f src/vnc.override
--- a/src/vnc.override Sun Jul 15 17:17:44 2007 -0400
+++ b/src/vnc.override Tue Jul 17 11:50:04 2007 -0400
@@ -11,3 +11,38 @@ ignore-glob
ignore-glob
*_get_type
%%
+override vnc_display_send_keys kwargs
+static PyObject*
+_wrap_vnc_display_send_keys(PyGObject *self,
+ PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = {"keys", NULL};
+ PyObject *keyList;
+ int ret, i, len;
+ guint *keys;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O:VncDisplay.send_keys", kwlist,
+ &keyList))
+ return;
+
+ if (!PyList_Check(keyList))
+ return;
+
+ len = PyList_Size(keyList);
+ keys = malloc(sizeof(guint)*len);
+ for (i = 0 ; i < len ; i++) {
+ PyObject *val;
+ char *sym;
+ val = PyList_GetItem(keyList, i);
+ sym = PyString_AsString(val);
+ if (!sym) {
+ free(keys);
+ return;
+ }
+ keys[i] = gdk_keyval_from_name(sym);
+ }
+
+ vnc_display_send_keys(VNC_DISPLAY(self->obj), keys, len);
+ free(keys);
+}
diff -r ab919470c43f src/vncdisplay.c
--- a/src/vncdisplay.c Sun Jul 15 17:17:44 2007 -0400
+++ b/src/vncdisplay.c Tue Jul 17 11:49:40 2007 -0400
@@ -582,6 +582,16 @@ gboolean vnc_display_open_name(VncDispla
return TRUE;
}
+void vnc_display_send_keys(VncDisplay *obj, const guint *keyvals, int nkeyvals)
+{
+ int i;
+ for (i = 0 ; i < nkeyvals ; i++)
+ gvnc_key_event(obj->priv->gvnc, 1, keyvals[i]);
+
+ for (i = (nkeyvals-1) ; i >= 0 ; i--)
+ gvnc_key_event(obj->priv->gvnc, 0, keyvals[i]);
+}
+
static void vnc_display_class_init(VncDisplayClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
diff -r ab919470c43f src/vncdisplay.h
--- a/src/vncdisplay.h Sun Jul 15 17:17:44 2007 -0400
+++ b/src/vncdisplay.h Tue Jul 17 11:32:54 2007 -0400
@@ -59,6 +59,8 @@ gboolean vnc_display_open_fd(VncDisplay
gboolean vnc_display_open_fd(VncDisplay *obj, int fd);
gboolean vnc_display_open_name(VncDisplay *obj, const char *host, const char *port);
+void vnc_display_send_keys(VncDisplay *obj, const guint *keyvals, int nkeyvals);
+
void vnc_display_set_password(VncDisplay *obj, const gchar *password);
void vnc_display_set_use_shm(VncDisplay *obj, gboolean enable);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]