Send Mouseclick to GUI through PowerShell
Posted: 4. Aug 2024, 22:28
I am trying to partially automate some tasks. I have the GUI running and would like to send some mouse clicks to it through PowerShell while still being able to manually intervene if necessary. I know for keys I can use:
Unfortunately, this is not possible for mouse clicks. So I tried to directly use the API:
However, this always yields the following error.
According to my understanding, this should work. But apparently it doesn't. Any help to get this to run would be appreciated!
Code: Select all
vboxmanage controlvm "vmname" keyboardputscancode <hex>
Code: Select all
$vBox = New-Object -ComObject VirtualBox.VirtualBox
$MACHINE = $vBox.FindMachine("Windows10")
$SESSION_ROOT = New-Object -ComObject VirtualBox.Session
$SESSION_GUEST = New-Object -ComObject VirtualBox.Session
$MACHINE.LockMachine($SESSION_ROOT, 1) # Locking the machine in Shared LockType
$SESSION_GUEST.Console.Mouse.putMouseEventAbvsolute(632, 687, 0, 0, 1)
Code: Select all
You cannot call a method on a null-valued expression.
At D:\loren\Documents\test.ps1:9 char:1
+ $SESSION_GUEST.Console.Mouse.putMouseEventAbvsolute(632, 687, 0, 0, 1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull