I have multiple cursors (which are actually forms) that can be controlled by their respective mouse. (1 cursor for 1 user).
I use SetCursorPos
to position the default cursor (the original system cursor) in a position that will not take away the focus from my application, and use ShowCursor(false)
to hide it.
I have a class that gets the handle of the mouse and the coordinates.
When the user clicks I use the SetCursorPos
and the mouse_event
to simulate the clicks in that particular position.
My simulated mouse clicks only work on certain components' OnClick event (It was supposed to be only buttons and labels, but I experimented with the stuff on my project just to know what will or won't work):
It works on:
- Buttons (TButton, TBitBtn, TAdvSmoothButton)
- TAdvGrid
- TMenuItem (but the direct child of the TMainMenu only)
- TRadioButton
It doesn't work on:
- TLabel
- Panels (TPanel, TAdvSmoothPanel)
- TCoolBar
- TMenuItem (not direct child of TMainMenu)
This is my code:
SetCursorPos(currentX , currentY);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Why doesn't it work on some components? Is there a workaround (because I would like to be able to click labels using mouse_event).
EDIT:
I tried checking if the clicking function was really called, so I put ShowMessage('clicked');
before the SetCursorPos and mouse_event...but strangely everything (minor edit: everything except MenuItems) works fine now (except for the fact that I have a Message popping out everytime I try to click something). Does anybody have an idea why this behaves that way?