 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Hülyesamu
Joined: 24 Sep 2004 Posts: 17
|
Posted: Tue Jan 01, 2008 3:28 pm Post subject: GUI: Dynamically generated buttons' gosubs |
|
|
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.
 |
|
| Back to top |
|
 |
Mustang
Joined: 17 May 2007 Posts: 415 Location: England
|
Posted: Tue Jan 01, 2008 4:04 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Wed Jan 02, 2008 5:36 am Post subject: |
|
|
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. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Hülyesamu
Joined: 24 Sep 2004 Posts: 17
|
Posted: Wed Jan 02, 2008 9:26 am Post subject: |
|
|
| Thanks, I'll try it. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|