I am trying to make a text editor from autohotkey.
Though, I am having trouble getting a button to insert text from a textbox into a file.
Here is my code
Gui, Add, Picture, x2 y-1 w1360 h40 , chars\greenbox.png
Gui, Add, Tab, x2 y39 w1360 h660 , Untilted Project
Gui, Font, S8 CBlue Bold, Verdana
Gui, Add, Button, x2 y-1 w90 h20 vSave_text, Save
Gui, Add, Edit, x2 y59 w1350 h-90 vUsertextinput, Edit
Gui, Add, Edit, x2 y59 w1290 h580 , ';Created Using ADI
Gui, Font, S8 CGreen Bold, Verdana
Gui, Show, x200 y139 h666 w1370, ADI Editor
Return
GuiClose:
ExitApp
Save_text:
FileAppend,
(
%Usertextinput%
), Projects\Untitled1.ahk
Your save button needs a g-label, not a variable, thus gSave_text.
To access the contents of the edit field you have to run GuiControlGet on it.
Here is a working example:
Gui, Add, Button, gSave_text, Save
Gui, Add, Edit, vUsertextinput, Test123
Gui, Show
Save_text() {
GuiControlGet, Usertextinput
FileAppend, %Usertextinput%, Projects\Untitled1.ahk
}
First time post & very thankful for all the useful posts on this site.
The following are two examples of working code that I have tweaked from this site and ahk's board. Credit goes out to ahk's "garry" for the combined boxes and to this site's "Robert Ilbrink" for the idea and functionality on the double click return current selection.
In short I have two pieces of working code that I would like to combine in the following way:
I am looking for a way to add the functionality of the double click in the second code example to the combined 'drop down + listbox' example shown below.
*Note: If I could keep the same button functionality that would be great because not only can you double click, but you can also hit enter with the highlighted text and it will retrieve and send the selected text.
First Program(Drop Down + ListBox)
gosub,ddlx
ACTIONMOVIS=MISSION|007
COMEDIMOVIS=QENGUIN|BRUSALL
HORRORMOVIS=RING|13GHOST
FANTASYMOVIE=AVATA|CHOCOLAT
Gui, Add, DropDownList,gAPLY x12 y70 w100 h100 vDROPDOWN, %LST%
Gui, Add, ListBox, x132 y70 w80 h180 vLISTBOXM
gui,Show
GuiControl,1: Choose,dropdown,Comedy ;-- << preselect
gosub,aply
return
;-- this can be interessant instead using a very long line --
DDLX:
LST=
(Ltrim Join|
Action
Horror
Comedy
Fantasy
Drama
)
return
APLY:
gui,1:submit,nohide
guicontrol,1:,LISTBOXM,|
listboxm=
If DROPDOWN=Action
LISTBOXM=%ACTIONMOVIS%
If DROPDOWN=Comedy
LISTBOXM=%COMEDIMOVIS%
If DROPDOWN=Horror
LISTBOXM=%HORRORMOVIS%
If DROPDOWN=Fantasy
LISTBOXM=%FANTASYMOVIE%
guicontrol,1:,LISTBOXM,%LISTBOXM%
listboxm=
return
GuiClose:
ExitApp
second program (ListBox with Double Click & Enter Functionality)
#SingleInstance Force
Gui, Add, ListBox, h150 w140 vMyListBox gMyListBox, MISSION|007|RING|13GHOST|QENGUIN|BRUSALL| AVATA|CHOCOLAT
Gui, Add, Button, Default, Input
Gui, +AlwaysOnTop
Gui, Show
return
MyListBox:
if A_GuiControlEvent <> DoubleClick
return
GuiControlGet, MyListBox ; Retrieve the ListBox's current selection.
Send, !{Esc}
Sleep, 200
SendInput, %MyListBox% `
return
ButtonInput:
Gui, Submit, NoHide
Send, !{Esc}
Sleep, 200
SendInput, %MyListBox% `
Return
GuiClose:
GuiEscape:
Gui, Destroy
ExitApp
Thanks again in advance for your ideas and suggestions.
-Alex
I have created Ribbon button for Outlook 2013 using c#.
And i have also set image for the ribbon.
Now on click of Ribbon button i want to change Ribbon Image.
Is it possible to achieve this using c#.?
Not sure how exactly you want it to work, but this could do the trick.
bool callback {get;set}
public Bitmap GetImage(IRibbonControl control)
{
switch (control.Id)
{
case "FooButtonId":
{
if(callback== true){
callback = false;
return new Bitmap(Properties.Resources.someimage1);
}else
callback =true;
return new Bitmap(Properties.Resources.someimage2);
}
}
}
}
This question is 3 yo but helped me to go further and I want to share this with you.
First, I accomplished this in VB.net so my code will be in VB.net. There are some online tools to convert the code into C#.
Second, I used a Toggle button instead of a Simple button.
Third, I used OnOff as a project setting in order to save the state of the Toggle button.
Step 1: Ribbon.xml file, code to place the toggle button on the ribbon.
Assuming you already have set up the tab and group tags in the file.
<toggleButton id="onoffTBTN" label="ON/OFF" showImage="true" onAction="OnOffToggle" getImage="OnOffImage"/>
Step 2: Ribbon.vb file, code to change the OnOff setting based on the Toggle button status(pressed or not) and forces to invalidate the custom control
Public Sub OnOffToggle(ByVal control As Office.IRibbonControl, ByVal pressed As Boolean)
My.Settings.OnOff = pressed
My.Settings.Save()
myRibbon.InvalidateControl("onoffTBTN")
End Sub
Step 3: Ribbon.vb file, reads the OnOff setting and changes the image accordingly. Have in mind that your images must have been added to your project resources in order to use them at My.Resources.*. I used png files that support transparent pixels. This function is called in two occasions, first when the Outlook starts and second when the toggle button is pressed and specifically with the command myRibbon.InvalidateControl("onoffTBTN").
Public Function OnOffImage(ByVal control As Office.IRibbonControl) As Drawing.Bitmap
Dim onoff As Boolean = My.Settings.OnOff
Select Case control.Id
Case "onoffTBTN"
If onoff = True Then
Return New Drawing.Bitmap(My.Resources._on)
Else
Return New Drawing.Bitmap(My.Resources.off)
End If
End Select
End Function
The only weird behaviour is when the OnOff setting has been set to TRUE. The correct image is displayed but the Toggle button looks unpressed. You have to click twice in order to set the OnOff setting to False.
In AutoHotKey, I want to have something like InputBox except that the text input is multiline. (i.e. like a textarea).
I want there to be two buttons, "Ok" and "Cancel", and I want them both to have accelerators. I want this code to be in the form of a function that I can call from other hotkeys to get multiline user input whenever I want. I want to be able to set the default text shown when the dialog is shown. I want the function to return null or empty string if the cancel button was pressed. I want the Esc key to cause the dialog to be closed as if the cancel button was pressed (and not exit the entire script). I want the dialog to show in the center of the screen, and to use the font that Windows usually uses for dialogs.
try this
!1::
MsgBox % MultiLineInputBox("Hello World:", "stuff, more stuff", "Custom Caption")
return
MultiLineInputBox(Text:="", Default:="", Caption:="Multi Line Input Box"){
static
ButtonOK:=ButtonCancel:= false
if !MultiLineInputBoxGui{
Gui, MultiLineInputBox: add, Text, r1 w600 , % Text
Gui, MultiLineInputBox: add, Edit, r10 w600 vMultiLineInputBox, % Default
Gui, MultiLineInputBox: add, Button, w60 gMultiLineInputBoxOK , &OK
Gui, MultiLineInputBox: add, Button, w60 x+10 gMultiLineInputBoxCancel, &Cancel
MultiLineInputBoxGui := true
}
GuiControl,MultiLineInputBox:, MultiLineInputBox, % Default
Gui, MultiLineInputBox: Show,, % Caption
SendMessage, 0xB1, 0, -1, Edit1, A
while !(ButtonOK||ButtonCancel)
continue
if ButtonCancel
return
Gui, MultiLineInputBox: Submit, NoHide
Gui, MultiLineInputBox: Cancel
return MultiLineInputBox
;----------------------
MultiLineInputBoxOK:
ButtonOK:= true
return
;----------------------
MultiLineInputBoxGuiEscape:
MultiLineInputBoxCancel:
ButtonCancel:= true
Gui, MultiLineInputBox: Cancel
return
}
You can keep it pretty short:
(tested and works)
MultiLineInput(Text:="Waiting for Input") {
Global MLI_Edit
Gui, Add, Edit, vMLI_Edit x2 y2 w396 r4
Gui, Add, Button, gMLI_OK x1 y63 w199 h30, &OK
Gui, Add, Button, gMLI_Cancel x200 y63 w199 h30, &Cancel
Gui, Show, h94 w400, %Text%
Goto, MLI_Wait
MLI_OK:
GuiControlGet, MLI_Edit
MLI_Cancel:
GuiEscape:
ReturnNow := True
MLI_Wait:
While (!ReturnNow)
Sleep, 100
Gui, Destroy
Return %MLI_Edit%
}
MsgBox % MultiLineInput("Tell me 5 things you like.")
This is what it could look like:
And here is what it returns printed in a MsgBox: Click
Updated version from answer https://stackoverflow.com/a/25800045/2043349 that fixes the bug that the Prompt Text won't be updated if you use the function multiple times:
MultiLineInputBox(Text:="", Default:="", Caption:="Multi Line Input Box")
{
static
ButtonOK:=ButtonCancel:= false
Gui GuiMLIB:New,, % Caption
Gui, add, Text, w600, % Text
Gui, add, Edit, r10 w600 vMLIBEdit, % Default
Gui, add, Button, w60 gMLIBOK , &OK
Gui, add, Button, w60 x+10 gMLIBCancel, &Cancel
Gui, Show
while !(ButtonOK||ButtonCancel)
continue
if ButtonCancel
return
Gui, Submit
return MLIBEdit
;----------------------
MLIBOK:
ButtonOK:= true
return
;----------------------
GuiMLIBGuiEscape:
GuiMLIBGuiClose:
MLIBCancel:
ButtonCancel:= true
Gui, Cancel
return
}
Here is a code:
Version 1 (with Gosub):
return
StartGui:
Gui, Add, Edit, x22 y19 w240 h120 vMyEdit, Here is default text
Gui, Add, Button, x22 y179 w100 h30 gGuiCloseOk, Ok
Gui, Add, Button, x162 y179 w100 h30 gGuiCloseCancel, Cancel
; Generated using SmartGUI Creator for SciTE
Gui, Show, w286 h231, My Gui Name
WinGetPos,,, Width, Height, My Gui Name
WinMove, My Gui Name,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
return
return
GuiCloseOK:
GuiControlGet, MyEdit
Gui, Destroy
return
GuiCloseCancel:
MyEdit:=""
Gui, Destroy
return
return
Esc::
Gui, Destroy
return
Place that code in your script anywhere you like. To call for the GUI add anywhere you want Gosub, StartGui. The content of Edit control you will get in MyEdit variable.
For example, if you want to call GUI by CTRL+ALT+z put that code in script anywhere you want:
return
!^z::
Gosub, StartGui
return
Version 2 (with function):
GuiFunc(DefaultText)
{
global MyEdit
MyEdit:=""
Gui, Add, Edit, x22 y19 w240 h120 vMyEdit, %DefaultText%
Gui, Add, Button, x22 y179 w100 h30 gGuiCloseOk, &Ok
Gui, Add, Button, x162 y179 w100 h30 gGuiCloseCancel, &Cancel
; Generated using SmartGUI Creator for SciTE
Gui, Show, w286 h231, My Gui Name
WinGetPos,,, Width, Height, My Gui Name
WinMove, My Gui Name,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
return
return
GuiCloseOK:
GuiControlGet, MyEdit
Gui, Destroy
return
GuiCloseCancel:
MyEdit:=""
Gui, Destroy
return
}
return
Esc::
Gui, Destroy
return
Place that code in your script anywhere you like. To call for the GUI, call GuiFunc(DefaultText) function with parameter that is text to display in Edit control by default. After running function global variable MyEdit is set to the content of Edit control. So you can use MyEdit variable anywhere outside the function. I know that you wanted function to return content of MyEdit variable but I tried it many ways with no success.
For example, put that code in your script anywhere you want. To call GUI press CTRL+ALT+z and to display content of MyEdit variable press CTRL+ALT+a :
return
!^z::
DefaultText:= "Here is default text"
GuiFunc(DefaultText)
return
return
!^a::
MsgBox, %MyEdit%
return
For both versions, if you decide to rename Window Title My Gui Name then keep in mind that you need to rename it in 3 places for script to work properly.
Also, always use AutoHotkey and its documenatation from http://ahkscript.org/ (current uptodate version, new official website)! AutoHotkey and its documentation from autohotkey.com is outdated and you may have some problems using them!
Based on alpha bravo's answer and Thierry Dalon's answer.
This is fixing the problem of either always having ErrorLevel=1 even when
the user clicks Ok button or not having ErrorLevel=1 when user clicks the cancel button or exits/interrupts the input box.
Also it uses WinWaitClose instead of while loop that seems better for me.
Removes unneeded lines having GuiControl and SendMessage.
MultiLineInputBox(Text:="", Defualt:="", Caption:="Multi Line Input Box"){
static
; futher helper variables
local is_interrupted := "" ; helper variable to know if submitted/interrupted [tn1]
Gui MultiLineInputBox:New,, % Caption
Gui, MultiLineInputBox: add, Text, r1 w600 , % Text
Gui, MultiLineInputBox: add, Edit, r10 w600 vMultiLineInputBoxContent, % DefaultText
Gui, MultiLineInputBox: add, Button, w60 gMultiLineInputBoxOK , &OK
Gui, MultiLineInputBox: add, Button, w60 x+10 gMultiLineInputBoxCancel, &Cancel
Gui, MultiLineInputBox: Show
Gui, MultiLineInputBox:+HwndMultiLineInputBox_hwnd
WinWaitClose, ahk_id %MultiLineInputBox_hwnd%
if (is_interrupted) {
ErrorLevel := 1
}
return MultiLineInputBoxContent
;----------------------
MultiLineInputBoxOK:
Gui, MultiLineInputBox:Submit
Gui, MultiLineInputBox:Destroy
return
;----------------------
MultiLineInputBoxCancel:
MultiLineInputBoxClose:
MultiLineInputBoxGuiEscape:
Gui, MultiLineInputBox: Cancel
Gui, MultiLineInputBox:Destroy
is_interrupted := True
return
}