[fpc-pascal]RE: XTest extension for fpc

Marc Santhoff M.Santhoff at t-online.de
Fri Apr 9 17:39:27 CEST 2004


Am Fr, den 09.04.2004 schrieb Rainer Hantsch um 15:08:
> Hello, Marc!

Hi!

> Do you have some code for me to see how FPC programs for X11 are written?
> 
> Nothing special, keep it simple, I primarily want to...
> a.)  see if it works with my old FPC 1.0.4
>      (yes, I still use this old version because it is the latest one
>      which also works on SuSE 5.2)

It should, if not there would be no GUI library at all.

> b.)  see how complicated it is.
>      Open a window, doo some little things inside,...

no idea, see below...

I think I'm not doing what you think about it (see my other answer):

The goal was to get a GTK+1.2 programme running without a standard
keyboard. Jeff Pohlmeyer kindly translated the header for the
XTest-extension which I'm using in the following way:

- a microcontroller picks up events from a matrix keyboard
- these event are sent as simple byte streams via USB to the generic
system device
- the gtk eventloop has the /dev/ugen0 port selected in an additional
input listener
- if there is an event, the callback is invoked by gtk
- the callback decodes the bytestream to a valid XKeySym
- this keysym is inserted in the XServers event loop by the XTest
extension

This part is working fine.

For getting an idea (and concept, to be honest) I used the source of
"xautomation" (no link at hand, sorry) which was translateable to pascal
mostly 1:1.

>From the impressions of using X directly i think it should be rather
simple to get started with some C code (AFAIR the X intrinsics docs
should have some). But, as said, my program is gtk-based.

So, look at this (not quite what you asked for ;):

procedure FakeKeyDecodeDown(display :  PDisplay; key: AnsiString );
var
	key2 : AnsiString;	
	kmod : AnsiString;
begin
	kmod := '';
	key2 := handleCombined(key, kmod);
	{$ifdef debug}writeln('FakeSendKey down: '+key+' '+kmod);{$endif}
	XTestFakeKeyEvent( display, FakeDecodeKey(display, key2), longint(TRUE), CurrentTime );
	FlushDisplay( display );
end; { keyDown }

procedure FakeKeyDecodeUp(display	:  PDisplay; key: AnsiString );
var
	key2 : AnsiString;	
	kmod : AnsiString;
begin
	kmod := '';
	key2 := handleCombined(key, kmod);
	{$ifdef debug}writeln('FakeSendKey up: '+key+' '+kmod);{$endif}
	XTestFakeKeyEvent( display, FakeDecodeKey(display, key), longint(FALSE), CurrentTime );
	FlushDisplay( display );
end; { keyUp }


function FakeDecodeKey(display : PDisplay; key: AnsiString ):TKeyCode;
var
	ks : TKeySym;
	kc : TKeyCode;
begin
	ks := XStringToKeysym(pchar(key));
	kc := XKeySymToKeycode( display, ks );
	result := kc;
end; { decodeKey }

procedure FlushDisplay(display	: PDisplay);
begin
	XFlush(display);
end; { FakeFlush }

Some lenghtly parts are missing and the XTest unit is unchanged from
Jeffs positing (I think, I'll diff it if important)

"handleCombined" does some decoding as in xte from xautomation (Shift, '&' -> 'ampersand', ...)

When I'm back from my vacation beginning tomorrow, maybe I can help a
little in translating a basic window C code to pascal.

Bye,
Marc






More information about the fpc-pascal mailing list