SendKeys Alernative for Linux lazarus / 1-Linux ---------------------------------------------------------------------- pixelink · 2025-10-28 23:40 I have am planning to move to Linux OS within a year or two. So, as I prepare to do so I am beginning to remake some of my windows apps (made in VS studio and Laz) to be Linux compatible However, I do have an app that uses the Windows Sendkeys functionality that performs "sendkeys" by sending text or OS commands to other applications on Windows. I am wondering.... is there an equivalent function in Laz (Free Pascal) that I can do something similar to SendKeys on other external programs? If not, what about a 3rd party package or something similar? Thanks for any suggestion! ---------------------------------------------------------------------- Handoko · 2025-10-29 03:41 I haven't tried, maybe MouseAndKeyInput unit is what you need. But it is under GPL license, which means you can't use it for closed-sourced projects. https://wiki.freepascal.org/MouseAndKeyInput ---------------------------------------------------------------------- Thaddy · 2025-10-29 05:58 I found several examples:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit inputsimulator;{$mode objfpc}{$linklib C}     {$linklib X11}   // unit keysym contains the key codes, part of X11 package.interface uses  X, Xlib, Xutil, keysym;  procedure Simulate_KeyPress(keySym: cardinal; shiftState: boolean = false);procedure Simulate_Mouse_Click(x, y: integer; button: integer = 1);procedure Simulate_Mouse_move(x, y: integer); implementation procedure Simulate_KeyPress(keySym: cardinal; shiftState: boolean = false);var  display: PDisplay;  event: TXKeyEvent;  keyCode: TKeyCode;begin  display := XOpenDisplay(nil);  if display = nil then Exit;    keyCode := XKeysymToKeycode(display, keySym);    event.display := display;  event.window := XDefaultRootWindow(display);  event.root := XDefaultRootWindow(display);  event.subwindow := None;  event.time := CurrentTime;  event.x := 1;  event.y := 1;  event.x_root := 1;  event.y_root := 1;  event.same_screen := 1;  event.keycode := keyCode;  event.state := 0;    if shiftState then    event.state := event.state or ShiftMask;    // Key press  event._type := KeyPress;  XSendEvent(display, XDefaultRootWindow(display), 1, KeyPressMask, @event);    // Small delay (optional)  // Sleep(10);    // Key release  event._type := KeyRelease;  XSendEvent(display, XDefaultRootWindow(display), 1, KeyReleaseMask, @event);    XFlush(display);  XCloseDisplay(display);end; procedure Simulate_Mouse_Click(x, y: integer; button: integer = 1);var  display: PDisplay;  event: TXButtonEvent;begin  display := XOpenDisplay(nil);  if display = nil then Exit;    // Move mouse to position  XWarpPointer(display, None, XDefaultRootWindow(display), 0, 0, 0, 0, x, y);  XFlush(display);    // Set up event  event.display := display;  event.window := XDefaultRootWindow(display);  event.root := XDefaultRootWindow(display);  event.subwindow := None;  event.time := CurrentTime;  event.x := x;  event.y := y;  event.x_root := x;  event.y_root := y;  event.same_screen := 1;  event.state := 0;  event.button := button;    // Press  event._type := ButtonPress;  XSendEvent(display, XDefaultRootWindow(display), 1, ButtonPressMask, @event);  XFlush(display);    // Release  event._type := ButtonRelease;  XSendEvent(display, XDefaultRootWindow(display), 1, ButtonReleaseMask, @event);  XFlush(display);    XCloseDisplay(display);end; procedure Simulate_Mouse_move(x, y: integer);var  display: PDisplay;begin  display := XOpenDisplay(nil);  if display = nil then Exit;    XWarpPointer(display, None, XDefaultRootWindow(display), 0, 0, 0, 0, x, y);  XFlush(display);  XCloseDisplay(display);end; end. Depends on X, not tested for Wayland, but XWayland works. You can also use xdotool, which works like this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure SimulateWithXdotool(command: string);begin  ExecuteProcess('/usr/bin/xdotool', command);end; // Usage examples:// SimulateWithXdotool('key a');           // Press 'a'// SimulateWithXdotool('key Ctrl+c');      // Press Ctrl+C// SimulateWithXdotool('mousemove 100 100'); // Move mouse// SimulateWithXdotool('click 1');         // Left clickNeeds xdotool installed: apt-get install xdotool I have more examples, but these need root priviliges. ---------------------------------------------------------------------- Thaddy · 2025-10-29 07:25 Side note: Does anybody know why I could not post my code without using underscores: the original code did not use underscores, but I get this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Simula]"]>BlockeduseClick(x, y: integer; button: integer = 1);procedure Simula]"]>BlockeduseMove(x, y: integer);So I had to add the underscores. Rather irritating...There should not be a security risk, because the code is contained in the codeblock. Anyway, the inputsimulator unit works, but note some key combinations can be reserved. (also the case with sendkeys) ---------------------------------------------------------------------- MarkMLl · 2025-10-29 07:39 At a somewhat lower level there's the events API https://www.kernel.org/doc/html/v4.18/input/event-codes.html and also see the evtest program: note that this is specifically input device codes, rather than "events" as in interrupts etc. What I don't know is whether it's possible to send events to a specific process (identified by PIC) or window (identified at the widget set level). MarkMLl ---------------------------------------------------------------------- Thaddy · 2025-10-29 07:43 That needs root privileges, so I left that out. If you are interested I can post for that too.. Using /dev/uinput and fpioctrl. Not really recommended and I doubt if it is very useful to OP. (Or anybody sane for that matter, usually discussions unfold that are not relevant to the question: a replacement for sendkeys) ---------------------------------------------------------------------- MarkMLl · 2025-10-29 10:49 Quote from: Thaddy on October 29, 2025, 08:43:08 amThat needs root privileges, so I left that out. No, user needs to be a member of the input group, or the program he's running needs appropriate capabilities. The sticking point is routing to a specific PID, window etc. MarkMLl ---------------------------------------------------------------------- pixelink · 2025-10-29 15:54 Thanks for the info! ---------------------------------------------------------------------- LemonParty · 2025-11-22 12:40 Quote from: MarkMLl on October 29, 2025, 08:39:15 amAt a somewhat lower level there's the events API https://www.kernel.org/doc/html/v4.18/input/event-codes.html and also see the evtest program: note that this is specifically input device codes, rather than "events" as in interrupts etc. What I don't know is whether it's possible to send events to a specific process (identified by PIC) or window (identified at the widget set level). MarkMLl I am intersting if someone successfully used this API. ---------------------------------------------------------------------- MarkMLl · 2025-11-22 18:16 Quote from: LemonParty on November 22, 2025, 01:40:50 pmI am intersting if someone successfully used this API. Not with my own code. I've got a slightly-modified version of mxk originally from http://welz.org.za/projects/mxk (not sure whether that site is still live **), but basically there should be plenty of examples around although they'll probably be written in C. However as I've said: the problem is that it's global, and oblivious to what program's running etc. To decide whether that API is going to be any use at all for you I suggest playing with evtest, noting that you'll need to be a member of the input group. MarkMLl ** https://web.archive.org/web/20150804022200/http://welz.org.za/proje cts/mxk ---------------------------------------------------------------------- LemonParty · 2025-11-23 17:07 That is quite a lot of C code. But it well written C code. Will be challenging to extract what needed from this sources. Thank you.