使用文本框和按钮的自动键

时间:2013-12-22 13:32:44

标签: autohotkey

需要一些文字框和按钮的帮助..

我一直在尝试使用“文本框”和“按钮”...但是我无法做到这一点......我需要从“文本框”字段中获取“值”并将其附加到按钮动作。即,无论用户给出什么输入......都需要将其附加到“URL”

示例:

如果用户在文本字段中输入“login”作为输入,则需要输入此输入并将其附加到“http://www.google.com/login

行动前: http://google.com

AfterAction: http://google.com/login

请帮助

这是我的代码:

Gui, Add, Edit, x162 y80 w140 h30 vUserInput, Type here
Gui, Add, Button, x182 y130 w100 h30 gAction, %"Action1" Action1:=http://www.google.om/
; Generated using SmartGUI Creator 4.0
Gui, Show, x127 y87 h379 w479, New GUI Window
Return

Action1:
Gui, Submit, NoHide
guiControlGet, txtVar,, UserInput
guiControl,, UserInput, %( txt++Action1 )

GuiClose:
ExitApp
return

谢谢和欢呼。

1 个答案:

答案 0 :(得分:3)

好的,你有一些误解和很多错误。 使用:= -vs- %是您的误解之一。

另外,您忽略了将gAction1作为按钮的goto标签。您有gAction,但没有名为Action的子广告。

另一个问题是,您未将return放在Action1标签的末尾。 这意味着在操作完成后,脚本将继续结束脚本...

您应真正阅读AutoHotkey文档!它将为您节省大量时间和头痛。另外,您应该看一些简单的例子。

但是,请尝试下面的脚本。无论您在框中输入什么内容,按下按钮后,都会附加到网址上。


;Now, it may be easier to define your re-usable variable here like this:
;myurl = http://www.google.com/
myurl := "http://www.google.com/"       ;this is exactly same as the previous line

Gui, Add, Edit, x162 y80 w300 h30 r1 vUserInput, Type here
Gui, Add, Button, x182 y130 w100 h30 gAction1, Action1      ;The last parameter is JUST the text on the button
;If you wanted to use a variable for the name instead of straight text, you would do this:
;Gui, Add, Button, x182 y130 w100 h30 gAction, %myurl%
;But what you were trying to do is to *assign* a variable instead of *using* a variable - that is, you CAN'T use action1:=value as the variable name

Gui, Show, x127 y87 h379 w479, New GUI Window
Return

Action1:  ;the name of this label is the same as the g-action of your button except without the "g" part.
    Gui, Submit, NoHide
    guiControlGet, UserInput        ;you can simply use the edit control's v-name as the output variable
    thisurl = %myurl%%UserInput%
    guiControl,,UserInput, %thisurl%    ;now set the url back to the control
return  ;if you don't put return here, the script will continue on and run the GuiClose label...

GuiClose:
    ExitApp
return  ;you can have this, but you don't need it here since the script will have ended before it gets run anyway.