need help applying awesome code to my own Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
yawikflame
Posts: 21
Joined: 02 Jan 2017, 06:19
Contact:

need help applying awesome code to my own

23 Feb 2017, 16:20

Hi there :D
i have seen a very cool script that allows you to open a ToolTip that opens after briefly holding down the middle mouse button and was hoping to apply the same functionality to my improvised interface that opens all kinds of things on my pc.
my interface is made out of GUI commands while the ToolTip is made as a menu which confuses me.
in simple words: i'd like to open my GUI as a ToolTip, from the last position of the mouse, just as the menu does, but keep all the buttons i have there and the pictures(with links) too.

my code:

Code: Select all

#SingleInstance, force


;   Gui Layout
;----------------
;---------------------------

Gui, Show, 
Gui, Font, cAqua

Gui, Font, s16
Gui, Add, Text, x160 y20 ,Hotkeys
;-------------------------------
Gui, Add, Picture, x100 y60 w200 h60 gYVC, C:\Users\yawik\Desktop\AHK\yawik\yvc.png
Gui, Add, Picture, x100 y+7 w200 h60 gYnet, C:\Users\yawik\Desktop\AHK\yawik\ynet.png
Gui, Add, Picture, x100 y+7 w200 h60 gLeagueOfLegends, C:\Riot Games\League of Legends\RADS\system\lol.ico
Gui, Add, Picture, x100 y+7 w200 h60 gMySite, C:\Users\yawik\Desktop\AHK\yawik\samsung.png
Gui, Add, Picture, x100 y+7 w200 h60 gYouTube, C:\Users\yawik\Desktop\AHK\yawik\youtube logo.png
Gui, Add, Picture, x100 y+7 w200 h60 gFacebook, C:\Users\yawik\Desktop\AHK\yawik\facebook logo.png


Gui, Add, Text, x420 y20 ,Scroll To Course
;-----------------------------------------
Gui, Add, Button, x400 y60 w200 h60 gInfi, Infi
Gui, Add, Button, x400 y+7 w200 h60 gAnglit, Anglit
Gui, Add, Button, x400 y+7 w200 h60 gHistabrut, Histabrut
Gui, Add, Button, x400 y+7 w200 h60 gMeida, Meida
Gui, Add, Button, x400 y+7 w200 h60 gCosmopolitiut, Cosmopolitiut
Gui, Add, Button, x400 y+7 w200 h60 gModelim, Modelim
Gui, Add, Button, x400 y+7 w200 h60 gTikshoret, Tikshoret


Gui, Add, Text, x740 y20 ,MiniGames
;----------------------------------
Gui, Add, Button, x910 y60 w70 h60 gHexxagonClose, Close
Gui, Add, Button, x910 y+7 w70 h60 gMemoryClose, Close
Gui, Add, Button, x910 y+7 w70 h60 gPearlsClose, Close

Gui, Add, Picture, x700 y60 w200 h60 gHexxagon, C:\Users\yawik\Desktop\AHK\test game\Hexxagon\Hexxagon.png
Gui, Add, Picture, x700 y+7 w200 h60 gMemory, C:\Users\yawik\Desktop\AHK\test game\Memory\Memory.jpg
Gui, Add, Picture, x700 y+7 w200 h60 gPearls, C:\Users\yawik\Desktop\AHK\test game\Pearls\Pearls.jpg




Gui, -AlwaysOnTop
Gui, color, Black
Gui, Show, x300 y150 w1000 h600, `t
Gui, Add, Picture, x0 y0 w1000 h600, C:\Users\yawik\Desktop\AHK\yawik\Interface.jpg
return



;   Lables
;----------------
;---------------------------

GuiClose:
	ExitApp
	return


LeagueOfLegends:
	Run, "C:\Riot Games\League of Legends\LeagueClient.exe"
	Sleep, 14000
	send, *****************
	send, {enter}
	ExitApp
	return

YVC:
	Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"  --profile-directory=Default --app-id=ilhainnnlldppdgnhjbnijkaodjcoidh
	sleep, 3000
	send, **************
	send, {Tab}
	send, *********
	send, {Enter}
	ExitApp
	return
	

Ynet:
	Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"  --profile-directory=Default --app-id=lhbfbhcmdfpilbfondnkehgcddhffpdd
	ExitApp
	return

MySite:
	Run, "https://samsungelectronics.000webhostapp.com"
	ExitApp
	return


YouTube:
	Run, "https://www.youtube.com/"
	ExitApp
	return

Facebook:
	Run, "https://www.facebook.com/"
	ExitApp
	return



Infi:
	Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\אינפי"
	ExitApp
	return

Anglit:
	Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\אנגלית מתקדמים ב'"
	ExitApp
	return

Histabrut:
	Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\מבוא להסתברות"
	ExitApp
	return

Meida:
	Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\מבוא למערכות מידע ניהוליות"
	ExitApp
	return
	
Cosmopolitiut:
	Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\מבוא לקוסמופוליטיות"
	ExitApp
	return
	
Modelim:
	Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\מודלים עסקיים"
	ExitApp
	return
	
Tikshoret:
	Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\תקשורת מחשבים"
	ExitApp
	return
	
	
	
	
Hexxagon:
Run, "C:\Users\yawik\Desktop\AHK\test game\Hexxagon\Hexxagon.ahk"
ExitApp
return

HexxagonClose:
IfWinExist, Hexxagon
    WinClose
	return

Memory:
	Run, "C:\Users\yawik\Desktop\AHK\test game\Memory\Memory.ahk"
	ExitApp
	return

MemoryClose:
IfWinExist, Memory
    WinClose
	return

Pearls:
	Run, "C:\Users\yawik\Desktop\AHK\test game\Pearls\Pearls.ahk"
	ExitApp
	return

PearlsClose:
IfWinExist, Pearls
    WinClose
	return




;   Functions
;----------------
;---------------------------




;   Hotkeys
;----------------
;---------------------------





;    anglit
-----------------
Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\אנגלית מתקדמים ב'"

;    cosmopolitiut
-----------------
Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\מבוא לקוסמופוליטיות"

;    histabrut
-----------------
Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\מבוא להסתברות"

;    infi
-----------------
Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\אינפי"

;    meida
-----------------
Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\מבוא למערכות מידע ניהוליות"

;    modelim
-----------------
Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\מודלים עסקיים"

;    tikshoret
-----------------
Run, "C:\Users\yawik\Google Drive\yawik\תשעז\סמסטר א\עמק יזרעאל\תקשורת מחשבים"



Esc::ExitApp

the ToolTip code(by Rajat):

Code: Select all

; You can set any title here for the menu:
MenuTitle = -=-=-=-=-=-=-=-

; This is how long the mouse button must be held to cause the menu to appear:
UMDelay = 20

SetFormat, float, 0.0
SetBatchLines, 10ms 
SetTitleMatchMode, 2
#SingleInstance


;___________________________________________
;_____Menu Definitions______________________

; Create / Edit Menu Items here.
; You can't use spaces in keys/values/section names.

; Don't worry about the order, the menu will be sorted.

MenuItems = Notepad/Calculator/Section 3/Section 4/Section 5


;___________________________________________
;______Dynamic menuitems here_______________

; Syntax:
;     Dyn# = MenuItem|Window title

Dyn1 = MS Word|- Microsoft Word
Dyn2 = Notepad II|- Notepad

;___________________________________________

Exit


;___________________________________________
;_____Menu Sections_________________________

; Create / Edit Menu Sections here.

Notepad:
Run, Notepad.exe
Return

Calculator:
Run, Calc
Return

Section3:
MsgBox, You selected 3
Return

Section4:
MsgBox, You selected 4
Return

Section5:
MsgBox, You selected 5
Return

MSWord:
msgbox, this is a dynamic entry (word)
Return

NotepadII:
msgbox, this is a dynamic entry (notepad)
Return


;___________________________________________
;_____Hotkey Section________________________

~MButton::
HowLong = 0
Loop
{
    HowLong ++
    Sleep, 10
    GetKeyState, MButton, MButton, P
    IfEqual, MButton, U, Break
}
IfLess, HowLong, %UMDelay%, Return


;prepares dynamic menu
DynMenu =
Loop
{
    IfEqual, Dyn%a_index%,, Break

    StringGetPos, ppos, dyn%a_index%, |
    StringLeft, item, dyn%a_index%, %ppos%
    ppos += 2
    StringMid, win, dyn%a_index%, %ppos%, 1000

    IfWinActive, %win%,
        DynMenu = %DynMenu%/%item%
}


;Joins sorted main menu and dynamic menu
Sort, MenuItems, D/
TempMenu = %MenuItems%%DynMenu%


;clears earlier entries
Loop
{
    IfEqual, MenuItem%a_index%,, Break
    MenuItem%a_index% =
}

;creates new entries
Loop, Parse, TempMenu, /
{
    MenuItem%a_index% = %a_loopfield%
}

;creates the menu
Menu = %MenuTitle%
Loop
{
    IfEqual, MenuItem%a_index%,, Break
    numItems ++
    StringTrimLeft, MenuText, MenuItem%a_index%, 0
    Menu = %Menu%`n%MenuText%
}

MouseGetPos, mX, mY
HotKey, ~LButton, MenuClick
HotKey, ~LButton, On
ToolTip, %Menu%, %mX%, %mY%
WinActivate, %MenuTitle%
Return


MenuClick:
HotKey, ~LButton, Off
IfWinNotActive, %MenuTitle%
{
    ToolTip
    Return
}

MouseGetPos, mX, mY
ToolTip
mY -= 3        ;space after which first line starts
mY /= 13    ;space taken by each line
IfLess, mY, 1, Return
IfGreater, mY, %numItems%, Return
StringTrimLeft, TargetSection, MenuItem%mY%, 0
StringReplace, TargetSection, TargetSection, %a_space%,, A
Gosub, %TargetSection%
Return


thanks in advance!

yawikflame
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: need help applying awesome code to my own  Topic is solved

23 Feb 2017, 16:29

So Rajat's code is like doing something blind. It creates a tooltip that is effectively an "image". It then captures the mouse location when you click. It will take that coordinate to calculate which part of the "image" your mouse was over, and run code based on that.

Your GUI is more interactive than that. What you can do is change where the Gui, Show command's coordinate are based on those returned by MouseGetPos (using CoordMode, Mouse, Screen), as part of an MButton hotkey. Additionally, you may want to remove the ExitApps and just use a Gui, Hide command.
User avatar
yawikflame
Posts: 21
Joined: 02 Jan 2017, 06:19
Contact:

Re: need help applying awesome code to my own

24 Feb 2017, 15:37

First of all, Thank you very much for the quick and insightful reply @Exaskryz!
Second, i would greatly appreciate further explanation on the practical part of the change in my code.
I've added this part of the hotkey you mentioned:

Code: Select all

~MButton::
HowLong = 0
Loop
{
    HowLong ++
    Sleep, 10
    GetKeyState, MButton, MButton, P
    IfEqual, MButton, U, Break
}
IfLess, HowLong, %UMDelay%, Return
but you lost me at the part of coordinates returned by MouseGetPos as part of that hotkey.

Code: Select all

Gui, Hide
command successfully applied.

thank you very much again!

yawik
User avatar
yawikflame
Posts: 21
Joined: 02 Jan 2017, 06:19
Contact:

Re: need help applying awesome code to my own

24 Feb 2017, 18:11

made it!
it took me a while to figure out each part of your recommendations but finally cracked it!

the code:

Code: Select all

UMDelay = 20
~MButton::
HowLong = 0
Loop
{
    HowLong ++
    Sleep, 10
    GetKeyState, MButton, MButton, P
    IfEqual, MButton, U, Break
}
IfLess, HowLong, %UMDelay%, Return
CoordMode, Mouse, Screen
MouseGetPos, mX, mY
Gui, Show, x%mX% y%mY% w300 h300, `tGui, -AlwaysOnTop
Gui, color, Black
Gui, Add, Picture, x0 y0 w1000 h600, C:\Users\yawik\Desktop\AHK\yawik\Interface.jpg
return
thanks a lot mate!

yawik

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: oktavimark, Rohwedder and 222 guests