Jump to content
Sign in to follow this  
Divine

How to get the input inserted into the UI

Recommended Posts

Divine

Hi guys! I was just wondering how to do this.

Let's say I wanted to do a program that could modify the writing put into Notepad by the user's choice. What I mean by that is my program will open Notepad, and then a box will pop up. Whatever the user puts into that box will then be sent to notepad. I was thinking of doing something like this:

$input = This is what I need to know how to get!
$Choice = $input
If Not ProcessExists("notepad.exe") Then
Run("notepad.exe")
Send($Choice)
EndIf

Would I use a GUIGetMsg() to see what the user has put in the box and send that to $input? I'm not too sure, and I wanted to see what you guys would say!

~Divine

Share this post


Link to post
Share on other sites
kylomas

Divine,

You could play with something like this

local $input = InputBox('*** My NotePad Input ***','','This is what I need to know how to get!')
If Not ProcessExists("notepad.exe") Then Run("notepad.exe")
WinWaitActive("[CLASS:Notepad]", "")
Send($input)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Divine

Alright thanks. Is there anyway I could insert the inputbox into a GUI so the user can send multiple lines at once?

Share this post


Link to post
Share on other sites
kylomas

Divine,

Here's a simple example of a gui with an edit control (for input).

See if you can work out how to get it to Notepad. (hint, see guictrlread in Help file)

Incidentally, why do you want to write to Notepad?

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
local $gui010 = guicreate('My Notepad Writer',300,300)
local $edt010 = guictrlcreateedit('',10,20,280,230,$ss_sunken)
local $btn010 = guictrlcreatebutton('Send',10,270,280,20)
     guisetstate()
while 1
switch guigetmsg()
case $gui_event_close
Exit
case $btn010
EndSwitch
WEnd

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Divine

I do not need a notepad writer, my true reason is just for the experience. I could also make a certain game, where one could type something and I could have a set answer for whatever the person typed. Also, building off your code, all I could manage was to run the program continually or run notepad, type nothing and just exit.

Share this post


Link to post
Share on other sites
JLogan3o13

I do not need a notepad writer, my true reason is just for the experience. I could also make a certain game

Divine, you need to specify exactly what you would like assistance with or what type of application you're trying to create/manipulate. "Just for the experience" doesn't give us a whole lot to go on in trying to assist :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Divine

Like I said, I could create a game that receives the input from whatever the user said, and have a set response for it.

Share this post


Link to post
Share on other sites
kylomas

Divine,

The boilerplate example I posted should give you a start. Define what you want to do (as JL is alluding to) and expand on this template using the Help file as a resource. This code was just a push to get you started.

kylomas

edit: just saw you last post...the code I posted is easily adapted to your task...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Divine

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
local $gui010 = guicreate('My Notepad Writer',300,300)
local $edt010 = guictrlcreateedit('',10,20,280,230,$ss_sunken)
local $btn010 = guictrlcreatebutton('Send',10,270,280,20)
     guisetstate()
while 1
switch guigetmsg()
case $gui_event_close
Exit
case $btn010
   $input = GUICtrlRead($edt010)
   Run("notepad.exe")
   WinActivate("Untitled - Notepad")
   Send($input)
   Exit
EndSwitch
WEnd

That's what I have so far, and I type something random in the box. It doesn't appear after I click send.

Share this post


Link to post
Share on other sites
Divine

Nevermind, I got it working, thank you!

Edited by Divine

Share this post


Link to post
Share on other sites
kylomas

If your purpose is to get the data in the edit control to a file just use the File* functions. For "Send" to work Notepad has to be running and be active..

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
kylomas

Divine,

Expanding on your "game" idea (and getting rid of the whole "Notepad" thing), this should be all you need to get started...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Local $gui010 = GUICreate('Number Guessing Game', 300, 300)
                guictrlcreatelabel('Guess the number!!!',10,20,100,20)
Local $inp010 = GUICtrlCreateinput('', 120, 20, 20, 20, $ss_sunken)
Local $btn010 = GUICtrlCreateButton('Guess', 10, 270, 280, 20)
Local $lbl010 = GUICtrlCreatelabel('', 10, 50, 280, 20)
GUISetState()

local $guess = random(1,10,1)

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $btn010
            if $inp010 = GUICtrlRead($inp010) = $guess then
                guictrlsetdata($lbl010,'Right !!!')
            Else
                guictrlsetdata($lbl010,'Wrong !!!')
                guictrlsetstate($inp010,$gui_focus)
            endif
    EndSwitch
WEnd

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Divine

Ok, now after I have inputted multiple edit boxes, it can not shift through them, do I have to include a special AutoItSetOption in the beginning of my script?

Share this post


Link to post
Share on other sites
kylomas

it can not shift through them

If this means get the data from them, then see guictrlread in the Help file.

kylomas

edit:

Now might be a good time to read the GUI Management sections in the Help file.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Divine

No, like I have 5 boxes lined up, and I can not press on any of them to click to type in another.

Share this post


Link to post
Share on other sites
BrewManNH

Can you explain that better, or better yet post some code showing what you're doing? Because I'm a bit lost as to what you're trying to say.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Divine

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("MacroEditer", 288, 206, 192, 124)
Global $Edit1 = GUICtrlCreateEdit("", 24, 8, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit2 = GUICtrlCreateEdit("", 24, 32, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit3 = GUICtrlCreateEdit("", 24, 56, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit4 = GUICtrlCreateEdit("", 24, 80, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit5 = GUICtrlCreateEdit("", 24, 104, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit6 = GUICtrlCreateEdit("", 24, 128, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit7 = GUICtrlCreateEdit("", 24, 152, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit8 = GUICtrlCreateEdit("", 24, 176, 193, 17)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Send?", 224, 8, 43, 17)
$Button2 = GUICtrlCreateButton("Send?", 224, 32, 43, 17)
$Button3 = GUICtrlCreateButton("Send?", 224, 56, 43, 17)
$Button4 = GUICtrlCreateButton("Send?", 224, 80, 43, 17)
$Button5 = GUICtrlCreateButton("Send?", 224, 104, 43, 17)
$Button6 = GUICtrlCreateButton("Send?", 224, 128, 43, 17)
$Button7 = GUICtrlCreateButton("Send?", 224, 152, 43, 17)
$Button8 = GUICtrlCreateButton("Send?", 224, 176, 43, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Edit: They are all lined up and ontop of each other, and by default it starts on the first box, but I can't seem to type anything or click in the rest of them.

Edited by Divine

Share this post


Link to post
Share on other sites
BrewManNH

Change the edit controls to Input controls and you won't have the problem. Something is causing the Edit controls to be too tall causing the problem you're seeing.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Divine

Oh, I thought it wouldn't work that way, turns out it did, thank you :P.

Share this post


Link to post
Share on other sites
kylomas

Divine,

When I add enough code to actually run what you posted I get the following...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("MacroEditer", 288, 206, 192, 124)
Global $Edit1 = GUICtrlCreateEdit("", 24, 8, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit2 = GUICtrlCreateEdit("", 24, 32, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit3 = GUICtrlCreateEdit("", 24, 56, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit4 = GUICtrlCreateEdit("", 24, 80, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit5 = GUICtrlCreateEdit("", 24, 104, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit6 = GUICtrlCreateEdit("", 24, 128, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit7 = GUICtrlCreateEdit("", 24, 152, 193, 17)
GUICtrlSetData(-1, "")
Global $Edit8 = GUICtrlCreateEdit("", 24, 176, 193, 17)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Send?", 224, 8, 43, 17)
$Button2 = GUICtrlCreateButton("Send?", 224, 32, 43, 17)
$Button3 = GUICtrlCreateButton("Send?", 224, 56, 43, 17)
$Button4 = GUICtrlCreateButton("Send?", 224, 80, 43, 17)
$Button5 = GUICtrlCreateButton("Send?", 224, 104, 43, 17)
$Button6 = GUICtrlCreateButton("Send?", 224, 128, 43, 17)
$Button7 = GUICtrlCreateButton("Send?", 224, 152, 43, 17)
$Button8 = GUICtrlCreateButton("Send?", 224, 176, 43, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
    EndSwitch
WEnd

I can input to each edit control just fine.

Again, read the Help file sections on GUI Managmant.

Also, code that actually runs will draw more attention than code that does not.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

×