Jump to content

Controlsend Input Help


 Share

Recommended Posts

GUICtrlCreateLabel("Word1", 8, 30)
GUICtrlCreateCombo("", 40, 27, 45)
$key1 = GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "0")
ControlSend("Notepad", '', '', "{"$Key1"}"
$time1 = GUICtrlCreateInput("Delay", 90, 27, 35)

That is a part of my code.

Everything worked fine UNTIL i added the controlsend

I want to make it type the key that the user picked in the combobox

I don't know hooow...

Link to comment
Share on other sites

Your code is going to place the return value of GUICtrlSetData in the $key1. GUICtrlSetData's purpose is merely to populate the control (combo box in this case) with data, not to extract data from it. The return value is used to indicate whether the function was successful or not e.g. 1 for success or 0 for failure (see the helpfile for full explanation). To see what the user has selected in the combo box you need to use GUICtrlRead (again, see the helpfile for full details).

Link to comment
Share on other sites

Example:

$handle = GUICtrlCreateCombo("", 50, 27, 45)
GUICtrlSetData($handle, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "0")
$key1 = GUICtrlRead($handle)

The last line will place the current value selected in the combo box into the $key1 variable. You will need to add more code so that your program actually waits for a value to be selected though.

Edited by sdraw107
Link to comment
Share on other sites

Your code is going to place the return value of GUICtrlSetData in the $key1. GUICtrlSetData's purpose is merely to populate the control (combo box in this case) with data, not to extract data from it. The return value is used to indicate whether the function was successful or not e.g. 1 for success or 0 for failure (see the helpfile for full explanation). To see what the user has selected in the combo box you need to use GUICtrlRead (again, see the helpfile for full details).

I learn better when I see an example.

I kinda sorta get what you mean, and I even looked at the helpfile, but I'm still kind of confused.

Sorry =/

Link to comment
Share on other sites

We were posting at the same time. See above for example :)

Ok, So now I have

GUICtrlCreateLabel("Word1", 8, 30)
$handle = GUICtrlCreateCombo("", 40, 27, 45)
GUICtrlSetData($handle, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "0")
$key1 = GuiCtrlRead($handle)
ControlSend("Notepad", '', '', "{"$key1"}"
$time1 = GUICtrlCreateInput("Delay", 90, 27, 35)

So, my guictrlread, reads what it in the $handle?

But ugh this is using way to much brain power...

Anyway, it doesn't work, I know it's because of the fact that i have $key in

ControlSend("Notepad", '', '', "{"$key1"}"
but I don't understand what to replace instead of that...
Link to comment
Share on other sites

If this is too much for your "brain power" maybe you should give up because what you tried to do is a basic thing. If that scares you, I can't imagine what something more advanced will do.

Have patience and read about commands, look at examples and don't give up too easy and you'll be able to learn.

Your script does not work because of this line:

ControlSend("Notepad", '', '', "{"$key1"}"

The wrong part is: "{"$key1"}" and the missing ")" at the end.

Just use:

ControlSend("Notepad", '', '', $key1)

and you'll see that it works.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

If this is too much for your "brain power" maybe you should give up because what you tried to do is a basic thing. If that scares you, I can't imagine what something more advanced will do.

Have patience and read about commands, look at examples and don't give up too easy and you'll be able to learn.

Your script does not work because of this line:

ControlSend("Notepad", '', '', "{"$key1"}"

The wrong part is: "{"$key1"}" and the missing ")" at the end.

Just use:

ControlSend("Notepad", '', '', $key1)

and you'll see that it works.

Lol, i figured it all out =P

Honestly, I feel so retarded right now, everything worked once I added the )... lol

Thanks tho =D

Link to comment
Share on other sites

I don't know what you mean - I can't see any "Start", I can't see any key presses. All I see in your script is the attempt to send something to Notepad, which was successfully resolved.

That's not my whole script...

;
;
; AutoIt Version: 1.0
; Language:       English
; Platform:       Win9x/NT
; Author:         Dgameman1
;
; Script Function:
;   Send Keys

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

GUICreate("DG v.1", 335, 100)

GUICtrlCreateLabel("Auto Words", 270, 10)

GUICtrlCreateLabel("word 1", 8, 30)
$handle = GUICtrlCreateCombo("", 40, 27, 45)
GUICtrlSetData($handle, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "0")
$key1 = GUICtrlRead($handle)
Send($Key1)
$time1 = GUICtrlCreateInput("Delay", 90, 27, 35)


GUICtrlCreateLabel("word 2", 8, 60)
GUICtrlCreateCombo("", 40, 54, 45)
$key2 = GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "0")
ControlSend("Notepad", '', '', $Key2)
$time2 = GUICtrlCreateInput("Delay", 90, 54, 35)

GUICtrlCreateLabel("word 3", 150, 30)
GUICtrlCreateCombo("", 182, 27, 45)
$key3 = GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "0")
ControlSend("Notepad", '', '', $Key3)
$time3 = GUICtrlCreateInput("Delay", 232, 27, 35)

GUICtrlCreateLabel("word 4", 150, 60)
GUICtrlCreateCombo("", 182, 54, 45)
$key4 = GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "0")
ControlSend("Notepad", '', '', $Key4)
$time4 = GUICtrlCreateInput("Delay", 232, 54, 35)

$startbutton = GUICtrlCreateButton("Start", 265, 70, 60)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()0
    
    Select  
        Case $msg = $startbutton
                $send1 = GUICtrlRead($key1)
                $sleep1 = GUICtrlRead($time1)
                            While 1 
            WinWaitActive("Untitled - Notepad")
                Send($send1)
                Sleep($sleep1)
            WEnd
                
        Case $msg = $GUI_EVENT_CLOSE
                GUIDelete()
                ExitLoop
            
    EndSelect
        
WEnd

EDIT: RELOOK AT CODE

Edited by Dgameman1
Link to comment
Share on other sites

I updated the code, still has the problem of

When I press start, it does not press the letter that I selected in the combobox.

The timer part works, but it seems that no matter what i put into my combobox, it still mashes 0 at the time that the user input...

Help? Any guidance?

Link to comment
Share on other sites

Another couple of problems:

WinWaitActive("Untitled - Notepad")

You are waiting for Notepad window to become active - but where is your Notepad? Do you have it already open? Are you making it active? Your script will be waiting endlessly for a Notepad window to become active. That's why is not working. You need to start Notepad at some point (Run) and to make the window active (WinActivate)

Second: your While/WEnd loop is endless; you have no way to quit that loop and will go on and on and on ...

Suggestion: Use a hotkey to exit the loop.

Third: you have changed only the first block of your code with the suggestion in this thread - change all the blocks.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

You're reading the wrong information and sending that to Notepad. You have scattered ControlSends all over your script in places that it shouldn't be for what you want to do. And you're trying to send garbage to Notepad when you do. Your GUICtrlRead's need to read from the controls, and not from the setdata command. Use GUICtrlRead($handle) instead of $send1 = GUICtrlRead($key1), $key1 makes no sense there. You set the value of $key1 right after you created the control, and it will never change which is why it's sending 0 all of the time.

There are so many problems with that script that a total rewrite would have to be done on it to even begin to figure out what it's supposed to be doing.

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

Link to comment
Share on other sites

Another couple of problems:

You are waiting for Notepad window to become active - but where is your Notepad? Do you have it already open? Are you making it active? Your script will be waiting endlessly for a Notepad window to become active. That's why is not working. You need to start Notepad at some point (Run) and to make the window active (WinActivate)

Second: your While/WEnd loop is endless; you have no way to quit that loop and will go on and on and on ...

Suggestion: Use a hotkey to exit the loop.

Third: you have changed only the first block of your code with the suggestion in this thread - change all the blocks.

1. I want that.

2. Thank you for the suggestion. I'll add a hotkey right now =D

3. That shouldn't matter right now because my

Select  
        Case $msg = $startbutton
                $send1 = GUICtrlRead($key1)
                $sleep1 = GUICtrlRead($time1)
                            While 1 
            WinWaitActive("Untitled - Notepad")
                Send($send1)
                Sleep($sleep1)
            WEnd

Shows that only $key1 will do anything. That's why I'm only changing what is key1 at the moment, but I'll do all the blocks just to see if it'll get fixed..

Link to comment
Share on other sites

Guys, I don't see what the problem is. Why is my coding so crappy? lol

This is the first time I've ever coded anything in autoit, and i appreciate you guys helping me. I would just like a simple reason and fix as to why it won't send what's in the combobox.

I also read what BrewManNH said and so i moved the value of $key1 around, and then it just wasn't able to run.

Helpp...?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...