AutoHotkey Community

It is currently May 26th, 2012, 1:57 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: January 1st, 2008, 4:28 pm 
Offline

Joined: September 24th, 2004, 4:42 pm
Posts: 22
Hi, I want to create a popup menu made of array of buttons that reads its content from a text file. (Ie. The first button has a text of THIS, and does THAT, both definded in the text file).

Certeanly, the buttons do the same, but with a different variable (more specifically, they send the keys that is written onto them: A "Kitchen" key says the keys k--i-t-c-h-e-n, etc)

Is it possible to do this in the AutoHotkey? Since the buttons need a "g label" gosub for everyone of them, but at a dynamically generated content it doesn't work.

:?:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 1st, 2008, 5:04 pm 
Offline

Joined: May 17th, 2007, 9:06 pm
Posts: 421
Location: England
Create a text file called "File.txt" with the following in it:
Code:
Name1,Text1
Name2,Text2
Name3,Text3

Then in the same folder a file with the following AHK script:
Code:
Loop, Read, File.txt
{
    Count := A_Index
    Loop, Parse, A_LoopReadLine, `,
    {
        If ( A_Index = 1 )
        {
            MenuName%Count% := A_LoopField
        }
        Else
        {
            MenuText%Count% := A_LoopField
        }
    }
}

Loop, %Count%
{
    Menu, MyMenu, Add, % MenuName%A_Index%, MenuHandler
}
Return

MenuHandler:
{
    MsgBox, % MenuText%A_ThisMenuItemPos%
    Return
}

^!a::
{
    Menu, MyMenu, Show
    Return
}

Use Ctrl+Alt+a to bring up the menu
Edit to your pleasing


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 2nd, 2008, 6:36 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
you can also do it with buttons. give them all the same glabel, and then make the label send/use %A_GuiControl%, which will contain up to the first 63 letters of the button's text.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 2nd, 2008, 10:26 am 
Offline

Joined: September 24th, 2004, 4:42 pm
Posts: 22
Thanks, I'll try it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2009, 12:03 am 
Offline

Joined: August 19th, 2008, 3:02 am
Posts: 6
I don't mean to raise a dead topic, but how does one assign the same glabel to the buttons?

I understand a little; report the button's name from the gosub using A_GUIControl, but how do you set that up in the first place?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2009, 12:27 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
The example above assigns each menu item to the label MenuHandler and determines which item was selected by checking A_ThisMenuItemPos.

If you're talking about using actual buttons, it's even easier: just assign each button to the same gLabel.
Code:
string = Mary had a little lamb

Loop, Parse, string, %A_Space%
 Gui, Add, Button, gLabel, %A_LoopField%
Gui, Show
return
GuiClose:
ExitApp

Label:
MsgBox, %A_GuiControl%
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2009, 1:11 am 
Offline

Joined: August 19th, 2008, 3:02 am
Posts: 6
thanks, I actually just figured it out.

What I didn't understand was that the glabel was activated every time I pressed the button; the manual just said that it ran the label immediately. In my mind, if the label was only run when the button was created, even if I made the glabel, I would've ended right back where I started. Then I just did it to see what would happen and voila.

Thanks for the help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2009, 3:53 pm 
Offline

Joined: April 14th, 2009, 10:06 am
Posts: 28
Im trying the same with one difference, i need the buttons to have the same text (i have a list of to-do things and i want a delete button at one side) How can i determine the button pressed and the label associated?

Example

List.

[Delete]Buy milk
[Delete]Buy Coffee
[Delete]Write a Book

I want to press the button near the label and identify in the subroutine the label near the button, is there a way?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2009, 4:41 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Here's a sample using buttons...
Code:
string = Mary had a little lamb

Loop, Parse, string, %A_Space%
{
 Gui, Add, Button, xm v%A_Index%, Delete
 Gui, Add, Edit, x+10 w100, %A_LoopField%
}
Gui, Show
return
GuiClose:
ExitApp

ButtonDelete:
GuiControl,,Edit%A_GuiControl%
return

...but it would be much nicer in a ListView.
Code:
list = Buy milk|Buy Coffee|Write a Book

Gui, Add, ListView, r10 -ReadOnly Checked, ToDo
Loop, Parse, list, |
 LV_Add("",A_LoopField)

Gui, Show
return
GuiClose:
ExitApp


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group