Gui and MosGetPos

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
j123258
Posts: 7
Joined: 08 Dec 2017, 12:12

Gui and MosGetPos

14 Dec 2017, 05:37

Hellow,I wrote a simple script,
I want to when I choose radio1 and press F2 (MosGetPos) ,the Gui can get the mosuse's x and y into the edit (x1,y1).
when I choose radio2 and press F2 (MosGetPos) , I also can get the information of mouse's and show it in the edit (x2,y2).

but it doesn't work as I excepted,how can I improve this script.

Code: Select all

Gui, Add, edit, vx1 ghotkey22
Gui, Add, edit, vy1 ghotkey22
Gui, Add, Radio ,  gHotkey22 ,Radio1
Gui, Add, edit, vx2 ghotkey33
Gui, Add, edit, vy2 ghotkey33
Gui, Add, Radio ,  gHotkey33, Radio2
Gui,show, w200 h200

F2::
{
	CoordMode ,Mouse,Relative
	MouseGetPos get_mousex, get_mousey
	varx = %get_mousex%
	vary = %get_mousey%
}
Hotkey22:
{
	 Gui,Submit,NoHide
	 GuiControl,,x1,%varx%
	 GuiControl,,y1,%vary%
	 return
}
Hotkey33:
{
	 Gui,Submit,NoHide
	 GuiControl,,x2,%varx%
	 GuiControl,,y2,%vary%
	 return
}

Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Gui and MosGetPos

14 Dec 2017, 06:57

Try this:

Code: Select all

Gui, Add, edit, x10 y010 vx1
Gui, Add, edit, x10 y035 vy1
Gui, Add, edit, x10 y080 vx2
Gui, Add, edit, x10 y105 vy2
Gui, Add, Radio , x10 y60  Checked gRadio, Radio1
Gui, Add, Radio , x10 y130 gRadio, Radio2
Gui,show, w200 h200
rd:=1
F2::
	CoordMode ,Mouse,Relative
	MouseGetPos get_mousex, get_mousey
	GuiControl,,% "x" rd,%get_mousex%
	GuiControl,,% "y" rd,%get_mousey%
return

Radio:
	Gui,Submit,NoHide
	rd := substr(A_GuiControl, -0)
return
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
j123258
Posts: 7
Joined: 08 Dec 2017, 12:12

Re: Gui and MosGetPos

14 Dec 2017, 07:17

@Odlanir that's what i want, thank you very much !!
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Gui and MosGetPos

14 Dec 2017, 07:19

Try this modified version.
I have deleted not needed g-Labels and added some return to prevent accessing parts of codes, which were desired to execute by g-labels.
Einfach nur ein toller Typ. :mrgreen:
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Gui and MosGetPos

14 Dec 2017, 07:46

divanebaba wrote:

Code: Select all

return ; <--- Needed to stop executing script
That return is not needed to stop executing script. It adds clarity. When unclear why AHK auto-adds this return, refer to the helpfile.
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Gui and MosGetPos

14 Dec 2017, 08:13

wolf_II wrote:... That return is not needed to stop executing script. ...
In the original script, he creates the Gui and don't stop his script.

Code: Select all

Gui, Add, Radio ,  gHotkey33, Radio2
Gui,show, w200 h200
<---- Here is a return needed, otherwise the script executes the F2-label
F2::
I think the return at shown line is urgent needed. Or do I deceive again?
Einfach nur ein toller Typ. :mrgreen:
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Gui and MosGetPos

14 Dec 2017, 08:27

No, your are overlooking the fact that AHK auto-inserts a Return. See https://autohotkey.com/docs/Scripts.htm#auto
There it says Auto-execute section stops at a hotkey label. Somewhere else it says why .. b/c of auto-inserting a Return
Maybe I learned about the auto-insert portion in the forum.

BTW: I don't suggest to omit the Return in question, I advise to always use it for clarity.
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Gui and MosGetPos

14 Dec 2017, 08:34

The help-file says:
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first).
Thanks. You're right. This information is new for me.
Einfach nur ein toller Typ. :mrgreen:
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Gui and MosGetPos

14 Dec 2017, 08:41

Try this:

Code: Select all



;-------------------------------------------------------------------------------
AutoExecute: ; auto-execute section of the script
;-------------------------------------------------------------------------------
    #NoEnv
    #SingleInstance, Force

; Return ; end of auto-execute section (commented out)



;-------------------------------------------------------------------------------
F12:: ; do stuff
;-------------------------------------------------------------------------------
    MsgBox, Hi, there!

Return
1. Run the script.
2. Right click tray icon to see most recent lines
3. Press F12 (the hotkey from script)
4. Press F5 (to refresh the most recent lines)

Notice the return there? I commented out my own to disable. I wanted to try the script not to stop autoexecuting (sort of).
The script will stop the auto-execute section when running into a hotkey label.

sorry for poor English, I hope you understand anyway. :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, vysmaty and 246 guests