Perhaps there is a better way, but in linux I fake key events with the program
that follows. I guess your program will have to detect whether it is under
linux/windows and, in windows, use Python for Windows Extensions download | SourceForge.net
Regards,
Ivan
keymodule.c-------------------
#include <Python.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>
static PyObject *
key_makeev(PyObject *self, PyObject *args)
{
Display *pDisplay = NULL;
int LocalScreen;
KeyCode kc;
int code;
int sts;
if (!PyArg_ParseTuple(args, "i", &code))
return NULL;
pDisplay = XOpenDisplay(NULL);
printf ("pDisplay = %lX\n", (long)pDisplay);
LocalScreen = DefaultScreen(pDisplay);
XSync(pDisplay,1);
kc = XKeysymToKeycode(pDisplay, code);
XTestFakeKeyEvent(pDisplay, kc, True, 10);
XTestFakeKeyEvent(pDisplay, kc, False, 10);
XFlush(pDisplay);
XCloseDisplay(pDisplay);
//XTestFakeKeyEvent(display, 51, True, 0);
//XTestFakeKeyEvent(display, 51, False, 0);
//printf("%d\n", code);
sts = 0;
return Py_BuildValue("i", sts);
}
static PyMethodDef KeyMethods = {
{"makeev", key_makeev, METH_VARARGS,
"Gera key events."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC
initkey(void)
{
(void) Py_InitModule("key", KeyMethods);
}
setup.py-------------
from distutils.core import setup, Extension
modulekey = Extension('key',
include_dirs = ['/usr/X11R6/include'],
libraries = ['Xtst'],
library_dirs = ['/usr/X11R6/lib'],
sources = ['keymodule.c'])
setup (name = 'PackageKey',
version = '1.0',
description = 'This is a key package',
ext_modules = [modulekey])
actually using:---------------
import key
key.makeev(0xFFBF) # fake 'F1' key, for instance
ยทยทยท
On Wednesday 03 November 2004 08:47, Tim Churchard wrote:
I am now writing in wxPython for both windows and Linux (Well I want my
program to run on both the same anyway, i'm actually writing it on linux)
Can anyone tell me, is it possible to send keyboard events to the system
from wxPython? (And if so can you point me in the right direction)