Control the VM intern?

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
gumpo03
Posts: 5
Joined: 14. Jan 2017, 17:43

Control the VM intern?

Post by gumpo03 »

Hey!
Is it possible to control the VM intern? Like to move the mouse to a certain point?

Thx!
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: Control the VM intern?

Post 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.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
gumpo03
Posts: 5
Joined: 14. Jan 2017, 17:43

Re: Control the VM intern?

Post 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!
Bypus
Posts: 33
Joined: 26. Sep 2017, 11:52

Re: Control the VM intern?

Post 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 ?
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: Control the VM intern?

Post 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
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Bypus
Posts: 33
Joined: 26. Sep 2017, 11:52

Re: Control the VM intern?

Post 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()
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: Control the VM intern?

Post 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
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply