Controlling multiple pointers with Xlib or xinput in ubuntu/linux - xlib

I'm creating a system that uses multiple cursors (pointers) in multiple xsessions. My computer has multiple video cards in it for controlling different monitors. I want to have a different cursor on each screen and control each. Each monitor is a different session.
I started using the xlib library in C to control the single cursor I have using the following command:
XWarpPointer(display,None,window,0,0,0,0,x,y);
This works perfectly for one cursor. Then I created a second cursor using xinput in the terminal:
>>xinput create-master second
and then I have two cursors on screen. I can go and control each with a separate mouse by using the reattach command:
>>xinput reattach MOUSEID POINTERID
The last step is to control each cursor separately using xlib. When I use the xWarpPointer command it just moves the original cursor around and I can't find a way to designate which cursor to control. I have also been unable to find a way to set the default pointer. You can see a list of all the pointers using "xinput list" in terminal. Does anyone know how I can
Thanks for the help!

You need to use XIWarpPointer request from XInput2 extension, it takes deviceid as parameter
Bool XIWarpPointer(
Display* display,
int deviceid,
Window src_win,
Window dst_win,
double src_x,
double src_y,
unsigned int src_width,
unsigned int src_height,
double dst_x,
double dst_y
);

Related

OpenGL on a secondary display

I have a Windows 7 system, a regular monitor as the primary display (serving as a desktop, etc.), and an additional screen attached to the same graphics card.
I want to write a program that takes control of the secondary display and uses it for fullscreen OpenGL rendering. I tried to enumerate displays with EnumDisplaySettings, pick the secondary display, create a device context associated with the display, set the pixel format on the DC, and create a WGL context associated with it. I can get this far without errors, but then the call to wglMakeCurrent fails for no apparent reason (return value is 0, GetLastError() is 0, and OpenGL does not function.)
The only way I could get it to work is to extend the desktop onto the secondary display (manually, from Windows display settings), create a window and move it onto the secondary display. Which is tolerable but undesirable (I don't want the secondary display to interfere with the desktop. For example, in this setup, I can move the mouse cursor from the desktop into the secondary display.) Is there a way to avoid this?
More generally, in order to get OpenGL to work on a display, do I need (1) to have the display attached to the desktop (or "a" desktop?), and/or (2) to have a window of my own on that display?
P.S. It seems that I might be able to get this to work with a third-party library such as glfw3, but I don't want extra baggage (I don't need 90% of functionality of glfw3) and I'd prefer to get this done directly through native API calls if possible.
Unfortunately the Windows graphics driver model does not allow to use displays independently. You will have to extend the desktop to the second display and create a fullscreen window on it. When it comes to constraining the mouse, the usual way is to hook into the system mouse events and whenever the mouse pointer is moved into the secondary screen remove it back to the primary screen.

Create a program that alters the execution of a windows application

I have a windows application which has several sub-forms. i have to navigate through 5 or 6 forms to reach the form i need. this is time consuming since i have to open it several times through the day and i do it daily.
my need: i dont have the source project for this application, i got it as an executable program, but i need to create some application that does these steps for me automatically. In other words i need to find a way to automatically click the buttons that navigate through the forms and opens the form i need from step one.
is there any way i can do this ?
There is indeed, though generic solutions already exist to perform just this kind of function to arbitrary programs.
You can use Spy++ or a resource-editor, like ResHack or ResEdit to look at the program and get the control ids of the navigation buttons.
Once done, you can get a handle to the program itself and then send messages to it's WindowProcedure that would be generated if the user clicked the controls with a mouse,
Another alternative, is to get the position of the running target application, after you've got it's HWND, by using the GetWindowRect function. You could then use this position along with vert/horiz distances to generate mouse events.
The two have more-or-less the same result, though some applications won't work with approach #1.
In one instance, you need to use Spy++ to get the control IDs.
In the other instance, you need to use an image editor to get the pixel offsets of the controls.
In both instances, you'll need to use FindWindow, along with the window's title-text in order to get a HWND handle.
You could use a combination of the two - asking the program itself with GetDlgItem for the handle of the controls you need to click. You could then query the control for its position, before using mouse_event to position the mouse above it and again to click it.
Quite a few ways to skin this cat, actually.
Pre-existing solutions like AutoIt are said to be very easy to use and will be much easier than coding a new program for each target.

Multiple cursor on windows application

I have founds some resource like this dealing with the subject of attaining multiple cursors on windows for more than one mouse attached to the system. My requirement is a little simpler but I need some inputs on it.
1) What I want is to invoke an application (lets say IE) and do mouse activity(hovering , clicking etc) on it. All of this while there should be no disturbance to the system cursor , which should be free to be used by the user of the desktop.
2)I understand that this can not be done using the windows cursor apis as the documentation always mentions "the cursor" and there is no concept of multiple cursors inbuilt.
3)
This leaves me to drawing a cursor on the target window. A bitmap perhaps and to move it randomly? What APIs will be of use here?
How do I simulate the visual effects that are actually done my actual cursor movement. Do I need to send messages to the target
window like WM_MOUSEMOVE , WM_SETCURSOR etc.?
Does sending mouse messages to the other window interfere with the mouse activities that the user is involved in currently? The
intention is not to disturb the user while the application runs.
Thanks for your inputs.
Create a separate window for each extra mouse that is installed, and put an image of the desired cursor in each window. Then use the Raw Input API to monitor activity on the extra mouses and move your windows around as needed, and use mouse_event() or SendInput() to send out your own mouse events (movements, clicks, etc) as needed.

Is there a standard way to create "combined" Windows cursors (e.g. Arrow+Stop)

It is well known that the WinAPI offers a number of default cursors. Among these, there is for example the default arrow (IDC_ARROW) and a "stop" icon (IDC_NO).
When using drag'n'drop in the Windows Explorer (e.g. in Windows 7), you can notice that Windows shows a combination of the two aforementioned cursors when dragging a file to some place where it cannot be dropped. This cursor does not exist as a .cur file and it cannot be configured in Windows' mouse setup.
I didn't stumble upon any obvious function to "combine" cursors, so I'm wondering if there's a default way in the WinAPI to create a cursor like the one in the example, or if I have to toy around with the two cursors manually and blit them together into a new cursor on my own.

Multiple mouse/mice/cursor?

How can I show another cursor for multiple mice?
I have two TMemos, two keyboards which can type into their respective TMemo, 2 mice and I need 2 cursors those.
If hypothetically, I can already detect which mouse is which. How can I make my own cursor to go along with it. (using Delphi)
Possibly along the lines of Multipoint
as an alternative, is there any software which can render more that one cursor. Like CPNMouse?
EDIT:
I found that I can use the mouse_event Function in windows, but I still don't have the visual representation of the cursor.
Cursors are just resources. Here is a good list of the standard cursors that can be used. TControl Defines a cursor property that can be set to the cursor that should be used when over a given control. You can also use Screen.Cursor to control the entire application cursor.
To define a custom cursor you use the following code.
{$R MyCustomCursors.RES}
const
crCustom1 = 1;
crCustom2 = 2;
...
Screen.Cursors[crCustom1] := LoadCursor(hInstance, 'CUSTOM1');
Screen.Cursors[crCustom2] := LoadCursor(hInstance, 'CUSTOM2');
...
Delphi was not designed by default to deal with multiple mouse pointers, but the I suspect most environments are not. The SDK you mention is the only source of information I have seen on using multiple mice at the same time in a single application. It however is .NET only, so using it would require Delphi Prism.
If you want to roll your own support for multiple mice the same trick of using WM_INPUT can can be used. Windows will treat both mice as the same. You will have to do custom painting of the mouse cursor by hand for the second mouse.
Windows doesn't support multiple mouse or keyboards. Since each process have only 1 input queue, Windows treats all similar input devices as the same single device. This can't be changed. End of story. Period.
But even if you can't do this on system wide scale - you still can do this in one particular application. You need to write a special driver and install it for the second mouse only. This driver should not pass mouse movements to usual consumer (input queue), but rather redirect input directly to your application.
You can use a already written drivers - for example, this one or the one, that you've already mentioned.
It can be simulated its action virtually from the original cursor by doing something seamingly fast

Resources