Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-03

XTest extension for fpc

10 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi!

Has anyone translated the XTest xtension of XFree86 to pascal yet?

I tried to h2pas this:
/usr/X11R6/include/X11/extensions/XTest.h

but don't know how to handle the "#if NeedFunctionPrototypes" declarations. I think they have to be rebuild as function headers with modifiers "extern; cdecl"?

TIA,
Marc

Jeff Pohlmeyer
Has anyone translated the XTest xtension of XFree86 to pascal yet?

I think it would look something like this:

unit XTest;
interface
uses x, xlib;
const
  X_XTestGetVersion = 0;
  X_XTestCompareCursor = 1;
  X_XTestFakeInput = 2;
  X_XTestGrabControl = 3;
  XTestNumberEvents = 0;
  XTestNumberErrors = 0;
  XTestMajorVersion = 2;
  XTestMinorVersion = 2;
  XTestExtensionName = 'XTEST';
type
  Bool =LongInt;
  TXInputClassInfo = record
    input_class : byte;
    event_type_base : byte;
  end;
  PXInputClassInfo = ^TXInputClassInfo;
  TXDevice = record
    device_id : TXID;
    num_classes : longint;
    classes : PXInputClassInfo;
  end;
  PXDevice = ^TXDevice;
function XTestQueryExtension(dpy:PDisplay; event_basep:Plongint; error_basep:Plongint;
  majorp:Plongint; minorp:Plongint):Bool;cdecl;external;
function XTestCompareCursorWithWindow(dpy:PDisplay; window:TWindow;
  cursor:TCursor):Bool;cdecl;external;
function XTestCompareCurrentCursorWithWindow(dpy:PDisplay;
  win:TWindow):Bool;cdecl;external;
function XTestFakeKeyEvent(dpy:PDisplay; keycode:dword; is_press:Bool;
  delay:dword):longint;cdecl;external;
function XTestFakeButtonEvent(dpy:PDisplay; button:dword; is_press:Bool;
  delay:dword):longint;cdecl;external;
function XTestFakeMotionEvent(dpy:PDisplay; screen:longint; x:longint; y:longint;
  delay:dword):longint;cdecl;external;
function XTestFakeRelativeMotionEvent(dpy:PDisplay; x:longint; y:longint;
  delay:dword):longint;cdecl;external;
function XTestFakeDeviceKeyEvent(dpy:PDisplay; dev:PXDevice; keycode:dword;
  is_press:Bool; axes:Plongint; n_axes:longint; delay:dword):longint;cdecl;external;
function XTestFakeDeviceButtonEvent(dpy:PDisplay; dev:PXDevice; button:dword;
  is_press:Bool; axes:Plongint; n_axes:longint; delay:dword):longint;cdecl;external;
function XTestFakeProximityEvent(dpy:PDisplay; dev:PXDevice;in_prox :Bool; axes:Plongint;
  n_axes:longint; delay :dword):longint;cdecl;external;
function XTestFakeDeviceMotionEvent(dpy:PDisplay; dev:PXDevice; is_relative:Bool;
  first_axis:longint; axes:Plongint; n_axes :longint; delay:dword):longint;cdecl;external;
function XTestGrabControl(dpy:PDisplay; impervious:Bool):longint;cdecl;external;
procedure XTestSetGContextOfGC(gc:TGC; gid:TGContext);cdecl;external;
procedure XTestSetVisualIDOfVisual(visual:PVisual; visualid:TVisualID);cdecl;external;
function XTestDiscard(dpy:PDisplay):TStatus;cdecl;external;
implementation
end.

( compiles, but not tested )

- Jeff

__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam http://mail.yahoo.com

Marc Santhoff
to Jeff Pohlmeyer
Show quoted text 5 lines
> Has anyone translated the XTest xtension of XFree86 to pascal yet? I think it would look something like this: unit XTest;

[...code snipped...]

( compiles, but not tested ) - Jeff

It does compile. Wow!

So I'll go testing, stay tuned for the result ...

Thank you, Jeff.

Bye,
Marc

Marc Santhoff
to Jeff Pohlmeyer: I think it would look something like this: unit XTest; interface uses x, xlib; const…
> Has anyone translated the XTest xtension of XFree86 to pascal yet? I think it would look something like this:

[...]

( compiles, but not tested )

I have only tested 'XTestFakeKeyEvent' so far and it does work!

Besides linking against Xtst (fpc -k-lXtst ...) there is only the problem of recoding chars to XKeySym's, but I think this is possible.

Bye and a big thanks again,
Marc

Marc Santhoff
to Marc Santhoff: [...code snipped...] It does compile. Wow! So I'll go testing, stay tuned for the result…

Am Mi, den 17.03.2004 schrieb Marc Santhoff um 10:18: [...]

It does compile. Wow! So I'll go testing, stay tuned for the result ...

It is only stupid rubbish, but i works.

For reference i use the source of the tool "xte" from the "xautomation" suite (see: http://hoopajoo.net/projects/xautomation.html).

Look:

program xtesttest;
uses sysutils, x, xlib, XTest;
var
	toSend : AnsiString;
	ch	   : AnsiString;
	i	   : integer;
	dpy	   : PDisplay;
	ks	   : TKeySym;
	kc	   : TKeyCode;
BEGIN
	dpy := XOpenDisplay(NIL);
	if NOT(dpy = NIL) then begin
		toSend := 'lalalalala';
		for i:= 0 to length(toSend)-1 do begin
			ch := copy(toSend,i+1,1);
			writeln(ch);
			ks := XStringToKeysym(pchar(ch));
			kc := XKeySymToKeycode( dpy, ks );
			XTestFakeKeyEvent( dpy, kc, longint(TRUE), CurrentTime );
			XTestFakeKeyEvent( dpy, kc, longint(FALSE), CurrentTime );
		end;
		XCloseDisplay( dpy );
	end;
END.

As already written, link against Xtst (fpc -k-lXtst ...).

Have fun,
Marc

Rainer Hantsch
to Marc Santhoff: [...] I have only tested 'XTestFakeKeyEvent' so far and it does work! Besides linking…

Hi!

Only a question of interest:
Are you trying to get FPC compiling X11 apps?

On Wed, 17 Mar 2004, Marc Santhoff wrote:

| Am Mi, den 17.03.2004 schrieb Jeff Pohlmeyer um 08:05: | > > Has anyone translated the XTest xtension of XFree86 to pascal yet? | >
| > I think it would look something like this:
| [...]
| >
| > ( compiles, but not tested )
|
| I have only tested 'XTestFakeKeyEvent' so far and it does work! |
| Besides linking against Xtst (fpc -k-lXtst ...) there is only the | problem of recoding chars to XKeySym's, but I think this is possible. |
| Bye and a big thanks again,
| Marc
|
|
|
| _______________________________________________
| fpc-pascal maillist -
| http://lists.freepascal.org/mailman/listinfo/fpc-pascal |

mfg

Ing. Rainer Hantsch

.---------------------------------------------------------------------. | \\|// Ing. Rainer HANTSCH - Hardware + Software | | (o o) Service - Support - WEB-Design und Programmierung | |--oOOo-(_)-oOOo------------------------------------------------------| | Ing. Rainer HANTSCH | mail: | | Khunngasse 21/20 | www: http://www.hantsch.co.at | | A-1030 Vienna | tel: +43-1-79885380 fax: +43-1-798853818 | | ** A u s t r i a ** | handy: +43-664-9194382 UID-Nr: ATU 11134002 | '---------------------------------------------------------------------'
Marc Santhoff
to Rainer Hantsch
Hi! Only a question of interest: Are you trying to get FPC compiling X11 apps?

Nope, I;m not trying but doing it actually. ;)

Yes, ask questions, if you like to.

Bye,
Marc

Rainer Hantsch
to Marc Santhoff: Nope, I;m not trying but doing it actually. ;) Yes, ask questions, if you like to. Marc

Hello, Marc!

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)
b.) see how complicated it is.
Open a window, doo some little things inside,...

On Thu, 18 Mar 2004, Marc Santhoff wrote:

| Am Do, den 18.03.2004 schrieb Rainer Hantsch um 10:40: | > Hi!
| >
| > Only a question of interest:
| > Are you trying to get FPC compiling X11 apps?
|
| Nope, I;m not trying but doing it actually. ;)
|
| Yes, ask questions, if you like to.
|
| Bye,
| Marc
|
|
|
|
| _______________________________________________
| fpc-pascal maillist -
| http://lists.freepascal.org/mailman/listinfo/fpc-pascal |

mfg

Ing. Rainer Hantsch

.---------------------------------------------------------------------. | \\|// Ing. Rainer HANTSCH - Hardware + Software | | (o o) Service - Support - WEB-Design und Programmierung | |--oOOo-(_)-oOOo------------------------------------------------------| | Ing. Rainer HANTSCH | mail: | | Khunngasse 21/20 | www: http://www.hantsch.co.at | | A-1030 Vienna | tel: +43-1-79885380 fax: +43-1-798853818 | | ** A u s t r i a ** | handy: +43-664-9194382 UID-Nr: ATU 11134002 | '---------------------------------------------------------------------'
Marc Santhoff
to Rainer Hantsch
Hello, Marc!

Hi!

Show quoted text 6 lines
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