Здравствуйте. Необходимо перехватывать нажатие и отпускание кнопки мыши. Написал следующий код в лазарусе:
program project1;
{$mode objfpc}{$H+}
uses
xlib, x, ctypes, sysutils;
procedure run;
var
d: PDisplay;
w,root: TWindow;
e: TXEvent;
msg: PChar;
s: cint;
mx , my : integer;
t : string;
begin
t := 'gg';
msg := PChar(t);
d := XOpenDisplay(nil);
if (d = nil) then
begin
WriteLn('[ModalShowX11Window] Cannot open display');
exit;
end;
s := DefaultScreen(d);
w := XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 200, 200, 1,
BlackPixel(d, s), WhitePixel(d, s));
XSelectInput(d, w, ExposureMask or KeyPressMask or pointermotionmask or
buttonpressmask or buttonreleasemask);
XMapWindow(d, w);
root := DefaultRootWindow(d);
XGrabPointer(d, root, False, ButtonPressMask or ButtonReleaseMask or
PointerMotionMask, GrabModeAsync, GrabModeAsync, None,
None, CurrentTime);
while (True) do
begin
XNextEvent(d, @e);
case e._type of
expose:
begin
XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));
end;
KeyPress:
begin
break;
end;
motionnotify:
begin
mx := e.xmotion.x;
my := e.xmotion.y;
t := inttostr(mx)+','+inttostr(my);
XDrawstring(d, w, DefaultGC(d, s), 50, 50, pchar(t), strlen(pchar(t)));
end;
buttonpress:
begin
mx := e.xmotion.x;
my := e.xmotion.y;
case e.xbutton.button of
button1:
t := 'left';
end;
end;
end;
end;
xungrabpointer( d,currenttime);
XCloseDisplay(d);
end;
begin
run;
end.