Page 1 of 1

Control the VM intern?

Posted: 19. Jan 2017, 11:43
by gumpo03
Hey!
Is it possible to control the VM intern? Like to move the mouse to a certain point?

Thx!

Re: Control the VM intern?

Posted: 19. Jan 2017, 11:58
by noteirak
Yes!

After locking an IMachine with a Shared lock, you will find that the IConsole object is available from the ISession object used for the lock.
on IConsole, you will find IConsole::mouse[1] which returns an IMouse object on which you can send mouse events to effetivly move the mouse or perform clicks.

[1] You will also find other devices like keyboard, display, etc.

Re: Control the VM intern?

Posted: 19. Jan 2017, 19:03
by gumpo03
Ok, do you have an example how to implement it using WebService?
Cause i have the Problem, that i don't really know how to get this ISession object of the VM I'm running this code at.

Have to say, that i have multiple VM's running at the same time this code, so it is not possible to implement just a constant with the name of the VM.

Btw. Thank you for your fast answer, really appreciate it!

Re: Control the VM intern?

Posted: 29. Sep 2017, 11:37
by Bypus
Hey, posting here because i i thought i was not worth it to create a post just for that.
When using releaseKeys() i feel like it doesn't release the keys.
Here is the code:

Code: Select all

def hotkey(key1, key2, key3 = None):
	if key3 is not None:
		codeStored = keyboard.putScanCodes([key1, key2, key3])
		keyboard.releaseKeys()
	else:
		codeStored = keyboard.putScanCodes([key1, key2])
		keyboard.releaseKeys()

# Action
hotkey(29, 33) # Ctrl-F
# Both are still getting pressed 

# With a single key
pressKey(33) # Enter
keyboard.releaseKeys()
# it keeps getting pressed
Is it a bug or am i doing something wrong ?

Re: Control the VM intern?

Posted: 29. Sep 2017, 12:29
by noteirak
most likely you need to put some waiting time between the two events. Normal humans don't press and release keys under a millisecond

Re: Control the VM intern?

Posted: 29. Sep 2017, 12:53
by Bypus
What if i do ? Just kidding.
I've tried it but keys are still pressed

Code: Select all

keyboard.putScanCode(29)
time.sleep(0.5)
keyboard.putScanCode(33)
time.sleep(0.5)
keyboard.releaseKeys()
## OR
keyboard.putScanCodes([29, 33])
time.sleep(0.5)
keyboard.releaseKeys()

Re: Control the VM intern?

Posted: 29. Sep 2017, 12:57
by noteirak
I think this area of the API is very rarely used by 3rd parties, so I don't know further I'm afraid. I don't even have experience with it.
The best approach in this situation is to go check how vboxmanage does it