Mouse button status outside the form (fullscreen) on Rasbian/arm lazarus / 31-LCL ---------------------------------------------------------------------- xardomain · 2023-08-18 16:13 Hi All, any pointer to find info about mouse buttons status on the screen? I need a Linux/arm solution, it easy to get the mouse position but not the status of the buttons. I need to acquire mouse position and button status and send to another raspberry, thanks. I don't need to emulate it (not here), I would just to have a device(a pi for example) that will tell me where the mouse is on its screen and when the user presses the one of the three button on the mouse. The data could be passed through network or even serial. At worst I could use a form that is the size of the screen and borderless (it should work I guess) but maybe there is a better solution. The screen is not really used, so even a full blown empty form will do but... TIA Giuseppe ---------------------------------------------------------------------- KodeZwerg · 2023-08-18 19:16 I am unsure about what you actual try to do but I suggest that you "uses mouse" and look into this unit. It offer a lot, I bet also things that you searching for. It is unknown to me how far it is compatible to your target. ---------------------------------------------------------------------- xardomain · 2023-08-18 21:04 >I am unsure about what you actual try to do but I suggest that you "uses mouse" and look into this unit. It offer a lot, I bet >also things that you searching for. >It is unknown to me how far it is compatible to your target. I can use mouse for the mouse position, but I am unable to detect mouse clicks. This is the reason of the request. I am unable to find this information/examples. I can find the solution for Windows, but I would  like it to be solved for Raspbian on PI, or even better cross platform. I need to create a dual headed computer(like a PI4), one monitor, one primary keyboard and a primary mouse are the real hw, normal stuff. On the same computer, but on the second monitor, I will have the output of a frame grabber "showing" the monitor of a target(another) computer. I would like to setup a second keyboard and a second mouse on the dual headed computer, completely independent from the target but also independent from the primary keyboard and the mouse, they need not to interfere each other. Connecting two keyboards and two mouses won't work because: 1) I cannot detect events from one particular keyboard or mouse connected 2) They are free to go from one monitor to another, I want them to be restricted to their monitors. On the dual headed computer I will record macro events from the keyboard and mouse, and will generate the clicks and the keystrokes using a couple of devices (like 2 PI zero W) that will regenerate the events for the target computer using USB gadget keyboard and mouse emulation. I could use a Teensy and or Arduino Nano but the PI Zero W would allow easier control. This is for the "regeneration" of the events captured but I would like to capture keyboard and mouse on the dual headed computer. Apparently, It would be like you are using the target computer from the dual headed because the monitor will be replicated and the secondary keyboard and secondary mouse events will be captured on the dual headed computer and regenerated using the keyboard and mouse emulation provided by USB gadget. I have one PI2 that could run just a Lazarus program that will transfer the mouse coordinates and button clicks to the dual headed computer but I am unable to extract mouse click information. Hope it is more clear (not easy at all). Giuseppe ---------------------------------------------------------------------- xardomain · 2023-08-18 21:46 Here it is using fullscreen form: procedure TForm1.FormCreate(Sender: TObject); begin       Form1.Top := 0;       Form1.Left := 0;       //Form1.Width:= 1920;       // Form1.Height:= 1080;       Form1.WindowState := wsFullScreen end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   if Button = mbleft then   begin     CheckBox1.Checked := TRUE;   end;   if Button = mbmiddle then   begin     CheckBox2.Checked := TRUE;   end;   if Button = mbright then   begin     CheckBox3.Checked := TRUE;   end; end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin        if Button = mbleft then   begin     CheckBox1.Checked := FALSE;   end;   if Button = mbmiddle then   begin     CheckBox2.Checked := FALSE;   end;   if Button = mbright then   begin     CheckBox3.Checked := FALSE;   end; end; procedure TForm1.Timer1Timer(Sender: TObject); begin   // butn := mbleft;   Label1.caption := 'X=' + IntToStr(Mouse.CursorPos.X);   Label2.caption := 'Y=' + IntToStr(Mouse.CursorPos.Y); end; Not exactly an elegant solution but it works. ---------------------------------------------------------------------- Joanna · 2023-08-19 14:48 Hi xardomain, just want to let you know that you should place your code inside the code viewer. It can be found when you modify your post...select code pascal and paste your code inside 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 code goes here Also you went to wrong place earlier which is why nobody answered. ---------------------------------------------------------------------- Lulu · 2023-08-19 19:50 Hi, may be this can help you. ---------------------------------------------------------------------- xardomain · 2023-08-21 06:03 Hi Lulu, that unit does not work for me, if I understood correctly it is for console application (text?) not gui. KodeZwerg, Since that raspberry will be dedicated for mouse and keyboard events I just created an app with a form maximized, I can get mouse movement events by using mouse.cursorpos.x and y. This is not available if I specify uses mouse clause btw. About keypress and mouse buttons event they trigger the form events, having the form maximized they always work. >Hi xardomain, just want to let you know that you should place your code inside the code viewer. Hi Joanna, thanks. >Also you went to wrong place earlier which is why nobody answered. Do you mean the IRC? Currently starting to add a Synapse client that will send mouse and keyboard events to the server, another raspberry. 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 TForm1.Timer1Timer(Sender: TObject);var test : longint;begin // Label1.caption := IntToStr(Mouse.CursorPos.x);  // Label2.caption := IntToStr(Mouse.CursorPos.y);  Label1.caption := IntToStr(Mouse.CursorPos.X);  Label2.caption := IntToStr(Mouse.CursorPos.y);  Label3.caption := IntToStr(Form1.Width);  Label4.caption := IntToStr(Form1.height)end; procedure TForm1.FormCreate(Sender: TObject);begin      Form1.Top := 0;      Form1.Left := 0;      // Form1.Width:= 1920;      // Form1.Height:= 1080;      Form1.KeyPreview := True;      Form1.WindowState := wsFullScreenend; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin    if Button = mbleft then  begin  CheckBox1.Checked := TRUE  end;  if Button = mbmiddle then  begin    CheckBox2.Checked := TRUE  end;  if Button = mbright then  begin    CheckBox3.Checked := TRUE  endend; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if Button = mbleft then  begin    CheckBox1.Checked := FALSE;  end;  if Button = mbmiddle then  begin  CheckBox2.Checked := FALSE;  end;  if Button = mbright then  begin    CheckBox3.Checked := FALSE;  end;end; ---------------------------------------------------------------------- VisualLab · 2023-08-21 10:57 Quote from: xardomain on August 18, 2023, 11:04:38 pmI would like to setup a second keyboard and a second mouse on the dual headed computer, completely independent from the target but also independent from the primary keyboard and the mouse, they need not to interfere each other. Connecting two keyboards and two mouses won't work because: 1) I cannot detect events from one particular keyboard or mouse connected 2) They are free to go from one monitor to another, I want them to be restricted to their monitors. On the dual headed computer I will record macro events from the keyboard and mouse, and will generate the clicks and the keystrokes using a couple of devices (like 2 PI zero W) that will regenerate the events for the target computer using USB gadget keyboard and mouse emulation. The success of this venture probably does not depend on Lazarus or FPC, but on the operating system. The system would have to allow for unambiguous identification of mice and keyboards (i.e. provide their identifiers). In the mouse handling events implemented in LCL controls, there is no information from which mouse (something like ID or similar) the data (coordinates, button IDs) comes from. So the mouse information (device ID or something) would have to be obtained from the system in some other way. Unfortunately, there is no standard GUI support in Linux - there is the old (and overly complicated) X Window and the still undercooked Wayland, which do not support all GUI functionality, but shift some of the functionality to desktop environment managers (GNOME, KDE, etc.). So the solution to your problem may exist, but it will require a lot of your own work and custom workarounds. --- EDIT: And could you describe (more generally) what kind of software you are developing and what goal you want to achieve? Maybe some alternative ideas for your application would emerge from such a discussion? Such brainstorming of many people can sometimes bring interesting results. ---------------------------------------------------------------------- xardomain · 2023-08-21 11:19 hi VisualLab, I have a couple of PI2 laying around so the solution is already found. One Pi2 will be a "dedicated" device, the keyboard and mouse will be connected to it. Its only purpose is to capture mouse and keyboard events. The form is maximixed (tested with a PI4 at the moment) and correctly detect mouses movements and mouse clicks in headless mode using VNC. Just in case I ordered a HDMI "dummy" plug. I will have to add some glue for handling keyboard events and send the data through a telnet connection to the dual headed pi. The dual headed pi will use a "native" keyboard and mouse to use the GUI (let's say left monitor) and keep a VLC maximixed on the right monitor. On the right monitor VLC will show maximixed the frame grabber with the output of the target computer. Reading the events from the PI2 will generate mouse and keyboard using a PI zero (hopefully one will be enough for mouse/keyboard, else one for the keyboard and another for the mouse). Not the easiest solution but doable. The "native" mouse will be free to roam from one monitor to another (maybe is possible to limit its movement to the left monitor) but will not influence the target machine (you need to generate events using the pi zero in gadget mode to transmit commands/events). Same goes for the "native" keyboard, it could not communicate with the target, unless the program running on the dual headed pi will decide to. I only need a pi wireless ready adapter, I had one N150 small dongle that I am unable to locate. That was nice not requiring driver setup and such. Giuseppe ---------------------------------------------------------------------- VisualLab · 2023-08-21 11:45 Quote from: xardomain on August 21, 2023, 01:19:52 pmReading the events from the PI2 will generate mouse and keyboard using a PI zero (hopefully one will be enough for mouse/keyboard, else one for the keyboard and another for the mouse). Well, operating systems currently in use were designed for workstations with the assumption that one keyboard, one mouse and one monitor would suffice for one user (except that support for more monitors in the most popular systems has somehow been patched over time). Anyway, from your description it seems that you solved the problem optimally. ---------------------------------------------------------------------- KodeZwerg · 2023-08-21 11:49 For your fullscreen demo, I would do it 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 TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);begin  // unit mouse must not be included!  Panel2.Caption := Format('x:%d - y:%d',[Mouse.CursorPos.X, Mouse.CursorPos.Y]);end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  // set all boxes according to the pressed button  CheckBox1.Checked := Button = mbLeft;  CheckBox2.Checked := Button = mbMiddle;  CheckBox3.Checked := Button = mbRight;  CheckBox4.Checked := Button = mbExtra1;  CheckBox5.Checked := Button = mbExtra2;end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  // reset all boxes  CheckBox1.Checked := False;  CheckBox2.Checked := False;  CheckBox3.Checked := False;  // problem, XButton does not fire event  CheckBox4.Checked := False;  CheckBox5.Checked := False;end;Attach those handler to all your window controls and you have a more accurate variant ---------------------------------------------------------------------- KodeZwerg · 2023-08-21 12:04 If you want to keep track of all mouse buttons that are pressed at same time: 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 TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  CheckBox1.Checked := ssLeft in Shift;  CheckBox2.Checked := ssMiddle in Shift;  CheckBox3.Checked := ssRight in Shift;  CheckBox4.Checked := ssExtra1 in Shift;  CheckBox5.Checked := ssExtra2 in Shift;end; ---------------------------------------------------------------------- xardomain · 2023-08-21 14:03 Many thanks for the suggestions. >attach those handler to all your window controls and you have a more accurate variant Controls may simply disappear once the code is good enough, after all it is a dedicated pi, no need to look at the screen, usually it will be headless. 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 CheckBox1.Checked := ssLeft in Shift;  CheckBox2.Checked := ssMiddle in Shift;  CheckBox3.Checked := ssRight in Shift;  CheckBox4.Checked := ssExtra1 in Shift;  CheckBox5.Checked := ssExtra2 in Shift; Can't decide between the two... 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   CheckBox1.Checked := Button = mbLeft;  CheckBox2.Checked := Button = mbMiddle;  CheckBox3.Checked := Button = mbRight;  CheckBox4.Checked := Button = mbExtra1;  CheckBox5.Checked := Button = mbExtra2;  Given you both reminded me that I may have two extra buttons (Yeah, I have a Razer fetish), I could detect wheelmouse as well. I tried 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 TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);begin  if (WheelDelta > 0) then Label5.Caption := 'Up!';  end;  if (WheelDelta < 0) then Label5.Caption := 'Down!';  Handled := trueend; And it works but how to detect when the wheel stops? TIA ---------------------------------------------------------------------- KodeZwerg · 2023-08-21 14:56 Feel free to try this. ---------------------------------------------------------------------- Joanna · 2023-08-21 15:26 Xardomain, yes , some places there are inactive. Feel free to message me if you need more information. ---------------------------------------------------------------------- xardomain · 2023-08-21 15:45 Thanks KodeZerg, basically you set a timer that tells you when no more action is present and reset. Good enough for me. Joanna, I would like to know where people hang, I returned to programming since a long time, thanks. Giuseppe ---------------------------------------------------------------------- Joanna · 2023-08-27 20:32 Quote from: xardomain on August 21, 2023, 05:45:17 pmThanks KodeZerg, basically you set a timer that tells you when no more action is present and reset. Good enough for me. Joanna, I would like to know where people hang, I returned to programming since a long time, thanks. Giuseppe It is in my signature