Control the VM intern?

Discussion about using the VirtualBox API, Tutorials, Samples.

Control the VM intern?

Postby gumpo03 » 19. Jan 2017, 11:43

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

Thx!
gumpo03
 
Posts: 5
Joined: 14. Jan 2017, 17:43

Re: Control the VM intern?

Postby noteirak » 19. Jan 2017, 11:58

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://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Control the VM intern?

Postby gumpo03 » 19. Jan 2017, 19:03

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!
gumpo03
 
Posts: 5
Joined: 14. Jan 2017, 17:43

Re: Control the VM intern?

Postby Bypus » 29. Sep 2017, 11:37

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   Expand viewCollapse view
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 ?
Bypus
 
Posts: 33
Joined: 26. Sep 2017, 11:52

Re: Control the VM intern?

Postby noteirak » 29. Sep 2017, 12:29

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://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Control the VM intern?

Postby Bypus » 29. Sep 2017, 12:53

What if i do ? Just kidding.
I've tried it but keys are still pressed
Code: Select all   Expand viewCollapse view
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()
Bypus
 
Posts: 33
Joined: 26. Sep 2017, 11:52

Re: Control the VM intern?

Postby noteirak » 29. Sep 2017, 12:57

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://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7


Return to The VirtualBox API

Who is online

Users browsing this forum: No registered users and 2 guests