PutMouseEventAbsolute not moving mouse

Discussion about using the VirtualBox API, Tutorials, Samples.
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

PutMouseEventAbsolute not moving mouse

Post by yojimbo »

Hi,
i'm trying to move the mouse of a guest win xp machine from a host windows 7 machine.
putMouseEventAbsolute does absolutely nothing.

Relative positioning works fine.

AbsoluteSupported returns true.
The guest has the latest guest additions installed.
I check the result of putMouseEventAbsolute, and it's not VBOX_E_IPRT_ERROR.


From what i understand under this circumstances, absolute positioning of mouse should be possible.
I read in an old forum post that even if the guest uses a (virtual) normal mouse (that is by its nature relative), guest additions installed should let you to use absolute positioning regardless any other circumstance.

Thanks for your help
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: PutMouseEventAbsolute not moving mouse

Post by noteirak »

A bit hard to help without detailed infos. Please read the API Discussion Forum - Posting Guidelines sticky.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

Re: PutMouseEventAbsolute not moving mouse

Post by yojimbo »

Really sorry.
VirtualBox-4.3.12-93733-Win running on windows 7 64 (tried to install 4.3.14, but I'm one of the few having problems with that version).
SDK 4.3.14-95030
connection: MSCOM
language of the program: C++

The code is a simple modification of the sample file in the SDK.

When putmouseeventabsolute is executed, the pointer just disappears, if I move the mouse, it appears again in the previous spot.
If putmouseevent is executed after the absolute call, the pointer appears again moved correctly.
I wanted to check the position of the pointer after the absolute call, when the pointer disappear, but I can't find the api call to get mouse position...

Thanks again.

Code: Select all

int main(int argc, char *argv[])
{
    HRESULT rc;
    IVirtualBox *virtualBox;

    do
    {
        /* Initialize the COM subsystem. */
        CoInitialize(NULL);

        /* Instantiate the VirtualBox root object. */
        rc = CoCreateInstance(CLSID_VirtualBox,       /* the VirtualBox base object */
                              NULL,                   /* no aggregation */
                              CLSCTX_LOCAL_SERVER,    /* the object lives in a server process on this machine */
                              IID_IVirtualBox,        /* IID of the interface */
                              (void**)&virtualBox);

        if (!SUCCEEDED(rc))
        {
            printf("Error creating VirtualBox instance! rc = 0x%x\n", rc);
            break;
        }

        listVMs(virtualBox);

        testErrorInfo(virtualBox);

        ISession *session = NULL;
        /* Create the session object. */
        rc = CoCreateInstance(CLSID_Session,        /* the VirtualBox base object */
                              NULL,                 /* no aggregation */
                              CLSCTX_INPROC_SERVER, /* the object lives in a server process on this machine */
                              IID_ISession,         /* IID of the interface */
                              (void**)&session);
        if (!SUCCEEDED(rc))
        {
            printf("Error creating Session instance! rc = 0x%x\n", rc);
            break;
        }
        printf("Session instance created.\n");

        IMachine *machine = NULL;
        rc = virtualBox->FindMachine(SysAllocString(L"win_xp_test_pc"), &machine);
        if (!SUCCEEDED(rc))
        {
            printf("Error vm not found\n");
            break;
        }
        printf("VM found.\n");
        machine->LockMachine (session, LockType_Shared);
        
        /* Get console object. */
        IConsole *console = NULL;
        IMouse *mouse = NULL;
        rc = session->get_Console(&console);
        if (!SUCCEEDED(rc))
        {
            printf("Error opening console\n");
            break;
        }
        printf("Console opened.\n");
        console->get_Mouse(&mouse);
        BOOL supported=false;
        mouse->get_AbsoluteSupported(&supported);
        if(supported)
        {
            printf("Absolute Supported\n");
        }
        rc = mouse->PutMouseEventAbsolute(100,100,0,0,0);
        if (rc==VBOX_E_IPRT_ERROR)
        {
            printf("Error sending mouse event\n");
            break;
        }
        rc = mouse->PutMouseEvent(10,10,0,0,0);
        /* Enable the following line to get a VM started. */
        //testStartVM(virtualBox);

        /* Release the VirtualBox object. */
        virtualBox->Release();

    } while (0);

    CoUninitialize();
    return 0;
}
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

Re: PutMouseEventAbsolute not moving mouse

Post by yojimbo »

I made some more tests, the return value of the PutMouseEventAbsolute call is 0.
I really cannot understand.
According to this:

https://www.virtualbox.org/pipermail/vb ... 12107.html

It should work.

Thanks again for all your support.
michael
Oracle Corporation
Posts: 682
Joined: 10. May 2007, 09:46
Contact:

Re: PutMouseEventAbsolute not moving mouse

Post by michael »

Sounds like the guest is expecting the host to draw the cursor. Normally when you send absolute position events it assumes that you are telling it the location of the host cursor and it stops drawing it itself. You can set the mouse attributes to tell it that the host does not support drawing the cursor itself.
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

Re: PutMouseEventAbsolute not moving mouse

Post by yojimbo »

Thanks for your reply.
I understand what you are suggesting, but needsHostCursor is a read-only attribute (it is False, by the way), there is not a set_NeedsHostCursor method.
And even if the guest expects the host to draw the cursor and stops drawing, the position of the cursor should change, a relative event, or whatever causes the mouse to move, should pick up where the absolute event sent the mouse, even if the cursor itself did not got drawn. Am I correct?
michael
Oracle Corporation
Posts: 682
Joined: 10. May 2007, 09:46
Contact:

Re: PutMouseEventAbsolute not moving mouse

Post by michael »

You are right, the capability saying whether the host can draw the pointer or not (hostCannotHWPointer) is not exposed via the API. What you did with the empty relative event after the absolute one is probably the simplest solution for what you want to achieve. You are also right that the guest should receive a position event (which is not fed back to the host) although the video driver does not draw the pointer.
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

Re: PutMouseEventAbsolute not moving mouse

Post by yojimbo »

Sorry, but I really can't understand.
If the event is received, but "fails", that is, it does not move the mouse to the new coordinates and causes the guest to stop drawing the cursor, isn't it better to return an error?
For what I want to achieve, I have to do a relative -10000, -10000, assuming that I'm at 1,1 and work from there with relative events. Hoping that the all stays in synch.
And that because I couldn't find a way to get the mouse position from the host, I begin to think that there is not a way, but it's odd. Knowing the mouse position from the host makes it very easy to send relative events to the guest.

Thanks for your help.
michael
Oracle Corporation
Posts: 682
Joined: 10. May 2007, 09:46
Contact:

Re: PutMouseEventAbsolute not moving mouse

Post by michael »

The event does (or should) move the mouse to the new co-ordinates. It also causes the guest to stop drawing the cursor. There is no way to get the position from the host because we never needed this. It would also require additional software, because only the guest operating system, not the guest hardware knows this position, so said additional software would need to ask the guest operating system about the position and report it back to the host. Since we normally know the position, since we just sent it, implementing an additional mechanism like this did not seem worth it to us.

As I said, sending an absolute event followed by a relative (0, 0) should be enough to get the guest to show the cursor at that place.
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

Re: PutMouseEventAbsolute not moving mouse

Post by yojimbo »

Hi,
really thanks for your advice.
But it does not work.
And hear this... I removed the relative call and left the absolute in a loop, every 500 ms it tries to move at 100,100.
If i push the left mouse button (touchpad button in this case) almost every time, it moves the mouse correctly.

Maybe the problem is in the 0 passed as the mouse button status? But the docs does not mention anything about special values, just 0 for button up and 1 for button down.


And sorry, you are right, the distinction between software and hardware is clear, but the guest additions add a layer, a bridge between the host and guest and I thought that there was some way to retrieve that information.

update:
I made more tests.
When I pass a value of 0 to the putMouseEventAbsolute, the effect is that described above.
When I pass a value of 1 - 7, it works as it should. The mouse really moves at the given coords. (The cursor still disappears)

I really don't know what to think.
At this point, I could think that it's really a bug.
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

Re: PutMouseEventAbsolute not moving mouse

Post by yojimbo »

I want to add another information.

The putmouseventabsolute call does works as expected if I send a mouse button click in addition to the movement information, as I mentioned in the previous post.
But I can confirm that it does work as expected even if I send the movement information without mouse clicks and press the physical mouse (touchpad in this case) button myself, while mouse integration is disabled, of course.

I would like to test the latest version of virtualbox, right now I'm on VirtualBox-4.3.12-93733, but right now i can't , because my laptop has problems with the latest version (HP security software).
michael
Oracle Corporation
Posts: 682
Joined: 10. May 2007, 09:46
Contact:

Re: PutMouseEventAbsolute not moving mouse

Post by michael »

You could give this build a try. It has a number of fixes related to interaction with security software.

https://www.virtualbox.org/download/tes ... 86-Win.exe
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

Re: PutMouseEventAbsolute not moving mouse

Post by yojimbo »

Hi,
sorry to bring this topic again to your attention.

I gave up (for now) on trying to solve the absolute mouse event problem.

I tried (just for fun) to build a client that runs in the guest and sends the request to move the mouse to a server running in the host.
It sends the current mouse position to the host that uses that starting position to move the mouse using the relative mouse event.

In some cases, if the mouse is (just for example) on 50,50 and I send a relative 4 x,3 y, it does not move of 4 x, 3 y pixels, but of 4,2 or 3,3 or 3,2.
I read somewhere that virtualbox, maybe at driver level, uses half-pixel position or something like that, but even if we count that into the equation, if I move the mouse by an integer number of pixels, even if the coords are stored in floats, I should end up with the movement of the correct number of pixels.

If the internal representation of the current mouse position is 50.9 and 50.6, I should end with 54.9 and 53.6, and the "rounding" should not change.

Sorry if I didn't explain it correctly, sometimes putting complex matters into words put my english to the test...

Thanks again for your help and your time!
michael
Oracle Corporation
Posts: 682
Joined: 10. May 2007, 09:46
Contact:

Re: PutMouseEventAbsolute not moving mouse

Post by michael »

The co-ordinates we sent are the ones requested plus 0.25 each direction (technically minus 0.75 due to the (1, 1) origin. This is done because X.Org and Windows do their rounding differently: X.Org rounds to the closest whole pixel value and Windows to the closest half. That might explain what you are seeing.
yojimbo
Posts: 12
Joined: 23. Jul 2014, 18:08

Re: PutMouseEventAbsolute not moving mouse

Post by yojimbo »

Sorry I didn't reply sooner, thanks for your help.
I understand what you are saying, but here we are talking of relative movement.
Sending the relative movement adding a 0,25 to the relative value does not make much sense. I can understand it for absolute movement, but for relative, if I want to move 5 pixels, and we are at whataver coordinates, we should end up 5 pixels away. Whatever the rounding of the original coordinates, it will be the same rounding of the new coordinates.
Example:
If we were at 12.65 x and 15,15 y, moving 5 pixels in each direction should send us at 17,65 and 20,15.
The rounding should then be applied to the "final" coordinates. So if we were at 12,5 and 15 rounded to half pixel, we should end at 17,5 and 20.
If 0.25 is added to the relative movement value, I would really like to understand why.

Thanks again for you help.
Post Reply