Sign in to follow this  
Followers 0
edena

GUI Input to Notepad

24 posts in this topic

I really want to make a GUI that when you type a text in the Input box and click a button a Notepad should pop up and the text you wrote in the GUI input box appears in the Notepad.

I've tried this for an hour now and could not figure out how to do it correctly. It seems that it's giving me errors and when I'm correcting those errors I'm getting no where.

Please help modify my code below:

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 218, 123, 192, 124)

$Input1 = GUICtrlCreateInput("Input1", 16, 24, 185, 21)

$Button1 = GUICtrlCreateButton("Button1", 56, 72, 107, 25)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case ($Input1)

ControlGetText ( "Form1", "Form1", Input1 )

Case ($Button1)

Run ("Notepad.exe")

ControlSend ( "Notepad", "Untitled - Notepad", $Input1, "" )

EndSwitch

WEnd

Thank You.

Share this post


Link to post
Share on other sites



I've corrected your code (see the differences?), and also added formatting for my tired eyes..

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("WinTitleMatchMode", 2)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 218, 123, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 16, 24, 185, 21)
$Button1 = GUICtrlCreateButton("Button1", 56, 72, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Run ("Notepad.exe")
            Sleep(250)
            ControlSend ("Notepad", "", "Edit1", GUICtrlRead($Input1))
    EndSwitch
WEnd

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Thank You very much for the script really appreciate it,

but when I tried it few more times it's now opening notepad and there's no text written on notepad.

What's seems to be the problem?

Thank You.

Share this post


Link to post
Share on other sites

I don't know. Try increasing the Sleep value. Remember, it's values are in milliseconds. So 500 is half a second, 1000 is 1 second..


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Maybe instead of sleep use WinWait()

Share this post


Link to post
Share on other sites

Okay thanks it's working

Please I have 2 more questions:

1. How do you place these signs "< >", in the GUI, instead of writing them down in the input box if you were to expand from the above code you given me.

For example:

In the GUI input box you write the word "text" and it shows something like this in the Notepad: "<text>"

2. I want to make two (2) GUI Input boxes with one (1) GUI button. The first GUI input should show <text> in the first line of Notepad and the Second GUI input should show in the second line of notepad.

For example:

In the GUI you have:

Input1 [text1 ]

Input2 [text2 ]

Button

So when the button is clicked notepad appears:

<text1> in first line

<text2> in second line

Thank You.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@monoscout999 - good call on WinWait

@edena - the & is a concatenation character, @CRLF is a carriage return/line feed macro. See what I did here? Besides adding another input control, I just added to the ControlSend string parameter. Oh, and I replaced the Sleep with WinWait. And Oh again, I replaced ControlSend with ControlSetText. They both work the same here, I don't know the difference between them..

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("WinTitleMatchMode", 2)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 218, 123, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 16, 24, 185, 21)
$Input2 = GUICtrlCreateInput("Input2", 16, 45, 185, 21)
$Button1 = GUICtrlCreateButton("Button1", 56, 72, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Run ("Notepad.exe")
            WinWait("Notepad")
            ControlSetText("Notepad", "", "Edit1", "<" & GUICtrlRead($Input1) & ">" & @CRLF & "<" & GUICtrlRead($Input2) & ">")
    EndSwitch
WEnd
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Wow!! Cool!!!

I kind of learned something thanks

but when I started to run the script it does only make the notepad appear but there are no text appearing on the notepad.

Share this post


Link to post
Share on other sites

Sorry I think I figured it out.

Didn't put the last script "WEnd"

Thank you very much for the help

Share this post


Link to post
Share on other sites

Thank you very much for the help

You bet.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I replaced ControlSend with ControlSetText. They both work the same here, I don't know the difference between them..

ControlSend will send each key after the other, like if some one were writing the text. ControlSetText will put the entire text at once into the Edit.

Share this post


Link to post
Share on other sites

So I guess SetKeyDelay would have not the effect on ControlSetText it would on ControlSend. I'll have to try that out later just to see. Thanks.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Can you save the file to the desktop and write the file name which is stated in Input2 also with another GUI Input3 for placing file extenstions, example: .txt or .au3?

Like you have this GUI:

Input1 (will write this on notepad like this: <Input1>)

Input2 (you will write down the file name)

Input3 (you will write the file extension option here . For example: .txt or .au3

Button

So when the button is pressed the file will appear on the desktop with the name you given from Input2 and with the file extension you given from Input3.

This is how far I've gone with the script can anyone help me with this:

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Opt("WinTitleMatchMode", 2)

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 212, 193, 192, 124)

$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)

$Input2 = GUICtrlCreateInput("Input2", 40, 64, 129, 21)

$Input3 = GUICtrlCreateInput("Input3", 40, 104, 129, 21)

$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

Run ("Notepad.exe")

WinWait("Notepad")

ControlSetText("Notepad", "", "Edit1", "<" & GUICtrlRead($Input1) & ">")

Sleep(1000)

Send("{ALTDOWN}f{ALTUP}a")

EndSwitch

WEnd

I've also tried: "FileSaveDialog" but cannot figure this out.

Thank You.

Share this post


Link to post
Share on other sites

You don't need to open Notepad to achieve all this. If you explain more what you want to achieve we can help with that.

Meanwhile try:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 212, 193, 192, 124)
GUICtrlCreateLabel("My Note:", 40, 10)
$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)
GUICtrlCreateLabel("File name:", 40, 50)
$Input2 = GUICtrlCreateInput("Input2", 40, 64, 129, 21)
GUICtrlCreateLabel("Extention:", 40, 90)
$Input3 = GUICtrlCreateInput("Input3", 40, 104, 129, 21)
$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Run("Notepad.exe")
WinWait("Notepad")
ControlSetText("Notepad", "", "Edit1", "<" & GUICtrlRead($Input1) & ">")
Sleep(1000)
Send("{ALTDOWN}f{ALTUP}a")
Sleep(500)
Send(GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))
Sleep(500)
Send("{enter}")
EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Thank you very much for the script I really appreciate it.

Okay,

I want to create a one page html page that is why I really want Input1 to work just for me to start writing the html script.

But the script you given me does not write down the html tags on the notepad which are this "<" and this ">" and of course text must be written between the tags.

You can see that the previous script writes the html tags with the text given by somdcomputerguy

Thank You.

Share this post


Link to post
Share on other sites

Try without notepad:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 212, 193, 192, 124)
GUICtrlCreateLabel("My Note:", 40, 10)
$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)
GUICtrlCreateLabel("File name:", 40, 50)
$Input2 = GUICtrlCreateInput("File", 40, 64, 129, 21)
GUICtrlCreateLabel("Extention:", 40, 90)
$Input3 = GUICtrlCreateInput("Html", 40, 104, 129, 21)
$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   $try = '<br />' & @CRLF
   $try &= '<table width=350 border=0 style="border-width: medium medium medium medium; border-spacing: 1px; border-style: solid solid solid solid; border-collapse: separate;">' & @CRLF
   $try &= '<tr>' & @CRLF
   $try &= '<td width=60%>' & GUICtrlRead($Input1) & '</td>'
   FileWrite(GUICtrlRead($Input2) & "." & GUICtrlRead($Input3), $try)
   Sleep(1000)
   ShellExecute(GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))
EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Thanks JoHanatCent

I think I've corrected the problem with the first script you given me. I've increased the Sleep to 1000 and it works fine.

Your second code is even better makes work more looking professional.

Thank You

Share this post


Link to post
Share on other sites

Sorry I'm back so excited with the scripts and I forgot something important.

How do you save the file in a destination like in the Desktop or in My Documents.

Thank You

Share this post


Link to post
Share on other sites

Hi! JohnOne,

This how I placed the "@DesktopDir" script in one of my lines but it still doesn't work. I'm really bad in scripts please can you or anyone help.

Send(@DesktopDir, GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))

The full script is here:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 212, 193, 192, 124)
GUICtrlCreateLabel("My Note:", 40, 10)
$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)
GUICtrlCreateLabel("File name:", 40, 50)
$Input2 = GUICtrlCreateInput("Input2", 40, 64, 129, 21)
GUICtrlCreateLabel("Extention:", 40, 90)
$Input3 = GUICtrlCreateInput("Input3", 40, 104, 129, 21)
$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Run("Notepad.exe")
WinWait("Notepad")
ControlSetText("Notepad", "", "Edit1", "<" & GUICtrlRead($Input1) & ">")
Sleep(1000)
Send("{ALTDOWN}f{ALTUP}a")
Sleep(1000)
Send(@DesktopDir, GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))
Sleep(1000)
Send("{enter}")
EndSwitch
WEnd

Thank You.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • IAMK
      By IAMK
      Hello,
       
      I have a script which uses a GUI with two buttons. It gets shown and hidden., and pressing the buttons (including their hotkeys) highlights the button, making you able to press enter the next time.
      However, I don't want that.
       
      I've tried using WinActivate() to make enter do things on another program, but the enter is still tied to the AutoIT GUI (which still has the button highlighted).
       
      Here's the important part of my code:
      $MY_GUI = GUICreate("Check.exe", 400, 300, ((@DesktopWidth / 2) - 200), -500) WinSetOnTop($MY_GUI, "", 1) ;Keeps the window on the top. $Button1 = GUICtrlCreateButton("Pass (Ctrl+P)", 40, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Fail (Ctrl+F)", 240, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $GUIText = GUICtrlCreateLabel("", 20, 10, 360, 230) GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif") GUICtrlSetData($GUIText, Execute($stepMessage[$step])) $showGUI = "True" GUISetState(@SW_SHOW) While($showGUI = "True") $buttonPressed = GUIGetMsg() Switch $buttonPressed Case $Button1 ;Pass $pass = "True" $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) Case $Button2 ;Fail $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) While($message = "") $message = InputBox("Check.exe", "Please enter the reason the step failed." & @CRLF, "", "", 300, 200, ((@DesktopWidth / 2) - 150), -400) WEnd Return $message EndSwitch WEnd Local $pass = "False" ;Whether "Pass" or "Fail" was pressed. Local $failLog = xxxfunc($pass) ;Returns a message to log if the step failed. ##THIS CALLS THE CODE SNIPPET ABOVE## FileWrite($file, _Now() & ": Step " & $step & getStatus($pass) & "and took " & Ceiling(TimerDiff($timer) / 1000) & " seconds." & @CRLF) If($failLog <> "") Then FileWrite($file, "Logged comment: " & $failLog & @CRLF) EndIf WinActivate("[TITLE:ProgramName]") ;Hotkeys: HotKeySet("^{p}", "pressPass") HotKeySet("^{f}", "pressFail") Func pressPass() $buttonPressed = $Button1 EndFunc Func pressFail() $buttonPressed = $Button2 EndFunc  
      The GUI's button/hotkey pressing works correctly.
      The same WinActivate code works in another script of mine.
      Together, WinActivate is not take "Active" away from the GUI's last-pressed button. How do I fix this?
       
      Thank you in advance.
    • fatpig
      By fatpig
      Dear AutoIT Community.
      I am currently working on a program that will display lots of images in a scroll down GUI.
      I create the GUI based on the number of images, which works fine.
      But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
      and will then populate on top of the images placed there before.
      For $i = 1 To $Images[0] ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images[1] Next I have found a limit at 32767 pixels for some GUI elements when googling around.
      Can someone tell me how to circumvent that?
      thanks!
      cheers
      Felix
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3

    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)