Virtualbox questions.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Virtualbox questions.

Post by mikeyww » 14 Jun 2022, 12:45

I cannot help with VirtualBox specifically, but to make the overall process easier, you could also start with something like this.

Code: Select all

InputBox, str1, VM, Please enter the virtual machine name.,, 300, 125
FileSelectFile, str2,, % StrReplace(A_AppData, "AppData\Roaming", "Downloads")
SendInput %str1%
SendInput %str2%

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Virtualbox questions.

Post by LAPIII » 15 Jun 2022, 12:25

To navigate in that setting window with AHK, I want to try screen and client coordinates. I just don't know how to get them.

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Virtualbox questions.

Post by mikeyww » 15 Jun 2022, 18:15

If you are navigating within one window, there is usually nothing special to do, because mouse moves, clicks, etc. use window coordinates by default. In those cases, the window's position does not matter. If needed, see :arrow: WinGetPos.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Virtualbox questions.

Post by LAPIII » 29 Jun 2022, 18:37

I'm going to replace the script you gave me because I want to use dropdown lists. I just don't know how to copy or store the information so that I can enter it in my script later:

Code: Select all

Gui, Add, Text,, Enter Operating System name:
Gui, Add, Edit, vtext
Gui, Add, Text,, Choose Type:
Gui, Add, DropdownList, vlist1, |Linux||
Gui, Add, Text,, Choose Version:
Gui, Add, DropdownList, vlist2, |Linux 2.2||Linux 2.4 (32-bit)||Linux 2.4 (64-bit)||Linux 2.6 / 3.x / 4.x (32-bit)||Linux 2.6 / 3.x / 4.x (64-bit)||Arch Linux (32-bit)||Arch Linux (64-bit)||Debian (32-bit)||Debian (64-bit)||Fedora (32-bit)||Fedora (64-bit)||Gentoo (32-bit)||Gentoo (64-bit)||Mandriva (32-bit)||Mandriva (64-bit)||Oracle (32-bit)||Oracle (64-bit)||Red Hat (32-bit)||Red Hat (64-bit)||openSUSE (32-bit)||openSUSE (64-bit)||Turbolinux (32-bit)||Turbolinux (64-bit)||Ubuntu (32-bit)||Ubuntu (64-bit)||Xandros (32-bit)||Xandros (64-bit)||Other Linux (32-bit)||Other Linux (64-bit)
Gui,Add,Button,gOk wp,Ok
Gui, Show,, New VM
Gui -MinimizeBox
return

~Enter::
Ok:
Gui,Submit
Last edited by LAPIII on 29 Jun 2022, 18:50, edited 2 times in total.

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Virtualbox questions.

Post by mikeyww » 29 Jun 2022, 18:49

Code: Select all

Gui, Font, s10
Gui, Add, DropdownList, w250 vlist2, Linux 2.2|Linux 2.4 (32-bit)|Linux 2.4 (64-bit)
Gui, Add, Button      , wp , OK
Gui, Show,, New VM
Return
ButtonOK:
Gui, Submit
MsgBox, 64, Version, %list2%
Return

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Virtualbox questions.

Post by LAPIII » 29 Jun 2022, 18:55

Let me explain further what I want. I want to store the input in the text box and the choice of the two drop-down menus. Would I need G-labels?

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Virtualbox questions.

Post by mikeyww » 29 Jun 2022, 19:04

When you submit the GUI, the data are stored in the variables that you have already provided. Please see the page cited here.

How to confirm: run the script.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Virtualbox questions.

Post by LAPIII » 29 Jun 2022, 19:08

Got it, thanks.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Virtualbox questions.

Post by LAPIII » 30 Jun 2022, 12:48

For this second list I'll need help because the Version needs to be chosen:

Create_Virtual_Machine 30-06-2022 01⦂32⦂21⦂719 PM.png
Create_Virtual_Machine 30-06-2022 01⦂32⦂21⦂719 PM.png (27.05 KiB) Viewed 1475 times

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Virtualbox questions.

Post by mikeyww » 30 Jun 2022, 12:55

When you submit the GUI, you have access to all of its variables.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Virtualbox questions.

Post by LAPIII » 30 Jun 2022, 16:03

I don't see how I can get AHK to do what I want. if I chose Arch Linux 64-bit from the GUI then I want AHK to choose it from Vitrtualbox' window. With the Version field in Virtualbox highlighted what would the code look like to pick this distribution?

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Virtualbox questions.

Post by mikeyww » 30 Jun 2022, 20:01

Sorry I do not use Virtualbox, cannot help you at that end of the issue. Others here may know.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Virtualbox questions.

Post by LAPIII » 30 Jun 2022, 20:21

Okay, is this how you write if the result of the variable vlist2 is Arch Linux 64-bit then do this statement:

Code: Select all

If (list2 = Arch Linux 64-bit)
{
    Statement
}

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Virtualbox questions.

Post by mikeyww » 30 Jun 2022, 20:33

Try it. Did it work? Silly to ask these questions that you can test yourself, right?

Use quotation marks.

Code: Select all

Gui, Font, s10
Gui, Add, DropdownList, w250 vlist2 , Linux 2.2|Linux 2.4 (32-bit)|Linux 2.4 (64-bit)
Gui, Add, Button      , wp   Default, OK
Gosub, F3
F3::Gui, Show,, New VM (F3 = show again)

ButtonOK:
Gui, Submit
If (list2 = "Linux 2.4 (64-bit)")
     MsgBox, 64, Result, Yep!
Else MsgBox, 48, Result, Nope!
Return
Useful reading: Expressions

I do recommend reading that page. It contains examples directly relevant to your question.

Useful excerpt among your readings:
Variable names in an expression are not enclosed in percent signs (except for pseudo-arrays and other double references). Consequently, literal strings must be enclosed in double quotes to distinguish them from variables.
Also: If:
Specifies one or more statements to execute if an expression evaluates to true.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Virtualbox questions.

Post by LAPIII » 09 Jul 2022, 13:03

When your code just fine:

Code: Select all

proc     = C:\Program Files\Oracle\VirtualBox\VirtualBox.exe
winTitle = ahk_exe %proc%
Run, % WinExist(winTitle) ? "" : proc
WinWait, %winTitle%,, 5
If !ErrorLevel {
 WinActivate
}

Why did changing it to:

Code: Select all

proc     = C:\Windows\System32\ApplicationFrameHost.exe ; activate Xbox Console Companion
winTitle = ahk_exe %proc%
Run, % WinExist(winTitle) ? "" : proc
WinWait, %winTitle%,, 5
If !ErrorLevel {
 WinActivate
}

Render this:

TEST_2.ahk 09-07-2022 01⦂59⦂11⦂662 PM.png
TEST_2.ahk 09-07-2022 01⦂59⦂11⦂662 PM.png (24.07 KiB) Viewed 1018 times

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Virtualbox questions.

Post by mikeyww » 09 Jul 2022, 16:55

This is apparently because the system cannot find the file that you specified.

You could try something like this.

Code: Select all

If WinExist("ahk_class ApplicationFrameWindow")
 WinActivate
Else runApp("Xbox Console Companion")

runApp(appName) { ; https://www.autohotkey.com/boards/viewtopic.php?p=438517#p438517
 For app in ComObjCreate("Shell.Application").NameSpace("shell:AppsFolder").Items
  Run, % app.Name = appName ? "explorer shell:appsFolder\" app.Path : ""
}

User avatar
pervect66
Posts: 27
Joined: 09 Jun 2021, 06:53

Re: Virtualbox questions.

Post by pervect66 » 10 Jul 2022, 07:09

@LAPIII You seem to try to run before you learnt to walk?

There is a reason most programming courses start with the example to write "Hello world!" to the console.

Try to open notepad using your code
If that works, try to open the file menu in notepad
etc....

That will give you an understanding of how things work, instead of trying to modify things you copied but don't understand yet.
AHK is not a hard language to learn, but you DO have to learn a few things......

Post Reply

Return to “Ask for Help (v1)”