Jump to content

Dynamic reading of input box, but when in focus


 Share

Recommended Posts

I have two input boxes. Let's just say Input A and Input B. 95% of the time Input B will be identical to Input A except it will have a small piece appended to it.

For example, I might append "_World" on to anything typed into A and store it in B:

Input A = Hello

Input B = Hello_World

or

Input A = Goodbye

Input B = Goodbye_World

But... I want to be able to change Input B (like override the value).

So... when I type in Input A (when it's focused) I want the data to automatically start populating Input B (concatinated with my suffix), but then if I move to Input B I want to be able to type something in there and not have Input A overwrite it unless I go back to Input A and start typing again.

Any Ideas? In the GUI control loop I can have something in there that just keeps reading A continuously, but it would constantly overwrite B.

Link to comment
Share on other sites

Not pretty but it works. Or at least may point you in the direction your looking for.

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 322)

$Input_A = GuiCtrlCreateInput("", 30, 10, 120, 40)
$Input_B = GuiCtrlCreateInput("", 30, 70, 120, 40)
$olda = ""
GuiSetState()
While 1
    $msg = GuiGetMsg()
    if(ControlGetFocus("MyGUI") == "Edit1") Then
        If(GUICtrlRead($Input_A) <> $olda) then
            $olda = GUICtrlRead($Input_A)
            GUICtrlSetData($Input_B,$olda)
            
        EndIf
    EndIf
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd
Exit
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Okay, here's how I acomplished it.... but i'm not 100% satisfied.

I first of all made my GUI. Then I used the AutoIt Info window. I selected the Input_A box for edit. And grabbed the class name. Then at the top of the control loop I check to see if that ClassName is in focus for the title of my window. This doesn't seem very flexible to me though. If that edit box gets moved around it might not be "Edit1" anymore. Once this project gets more complex it might become "Edit23" or move around as I add more fields. So each time, I'll have verify the class name with the Infowindow. I'll probably also want to add something to my If statement to make sure this window is in focus.

Does anybody have any improvements on this?

#include <GUIConstants.au3>

;basic gui with two input fields
GUICreate("My GUI")
$Input_A = GuiCtrlCreateInput("", 30, 30, 130, 20)
$Input_B = GuiCtrlCreateInput("", 30, 70, 130, 20)
GUISetState (@SW_SHOW)  ; will display an empty dialog box


; Control Loop
While 1
    
; Continuosly watch the Input_A box for changes if it is in focus.  
; otherwise, ignore it
; Edit1 was obtained by using the AutoIt Window Info Tool. 
    If(ControlGetFocus ( "My GUI" ) == "Edit1") Then GuiCtrlSetData($Input_B, GuiCtrlRead($Input_A))
    
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        
Wend

Hopefully someday AutoIt will have onfocus and onblur like Javascript does. I'd like to capture the data onblur actually.

Thanks!

Link to comment
Share on other sites

If your only need to change inputb when inputa changes I would'nt worry about if it has focus or not, then you won't need to worry about what the classname is

As to the window having focus or not you might try WinGetState

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

If I don't check for focus it continously updates. Which isn't a problem until I try to type into Input B... it won't let you really type anything into it because A keeps overwriting it. I tried it without checking for focus first just to see what would happen.

Link to comment
Share on other sites

download my Title Changer program from http://www.autoitscript.com/fileman/users/public/Xenogis/ and look at how i dynamicly change window titles that might help

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

I think burrup came up with this script that does what you want to do.

#include <GUIConstants.au3>

GUICreate("Test")

$test1 = GUICtrlCreateInput ( "0000", 2, 2,40,-1,$ES_NUMBER)
$test2 = GUICtrlCreateInput ( "This is a test", 2, 30,70,-1)

$test3 = GUICtrlCreateLabel ( "text", 100, 2, 100, -1)

GUISetState()

$changed = GUICtrlRead ($test3)

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
   If GUICtrlRead ($test1) > 9999 Then
      GUICtrlSetData ($test1, "9999")
   EndIf
   If $changed <> GUICtrlRead ($test1) & " - " & GUICtrlRead ($test2) Then
      GUICtrlSetData ($test3, GUICtrlRead ($test1) & " - " & GUICtrlRead ($test2))
   EndIf
   $changed = GUICtrlRead ($test3)
Wend

I can't remember the thread/link to the original post.

Burrup... this is correct no? Your code?

RocTx

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...