Jump to content

Trigger An Event When An Input Is Focussed


Recommended Posts

Hi,

I'm currently writing a program for an unattended installation, but I want to be able to specify some parameters before the installer starts.

I've created a timer using Adlib (also using Adlib for some other functions), but I want to stop the timer when an input-field is focussed (GUICtrlCreateInput).

I tried this, but it doesn't work as expected, even better: nothing happens!

If GUICtrlGetState($elm) = $GUI_FOCUSThen
    AutoStartClear()
EndIf

Any suggestions on how I can invoke that function when a control is focussed?

P.S. I've also created a serial number box using some functions, it automatically adds dashes and removes odd characters like $^#&, i've attached the script. If somebody has got a better solution for a serial-number-box, I'd like to hear it :( (A masked edit-control would be very nice :))

serial2.au3

Edited by JamesNL
Link to comment
Share on other sites

aybe..

; Serialcode formatteren
; (c) Alex van Herwijnen

#Include <GUIConstants.au3>
;AdlibEnable("FormatSerial")
;~ #NoTrayIcon
$myGui = GUICreate("", 350, 50, -1, -1, $WS_POPUP)
GUISetBkColor(0x4E6FD6)
_GuiRoundCorners($myGui, 0, 0, 50, 50)

$input1 = GUICtrlCreateInput("", 25,15,280, -1, $ES_UPPERCASE)
GUICtrlSetLimit(-1, 29);
GUICtrlSetFont(-1, 10, 400, 0, "Lucida Console")
$GO = GUICtrlCreateButton("Go", 305,15,30, 20, $ES_UPPERCASE)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()  
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $GO
            AdlibEnable("FormatSerial")
        ; or just FormatSerial()
    EndSelect
    Sleep(1)
WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

Where is $elm in your script, what is $elm? If you know what the ClassNameNN of the Control you want to do something if it has focus then you could do:

If ControlFocus($Main) = 'Edit1' Then

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

$elm is an earlier created input field, using GUICtrlCreateInput.

SmOke_N: that's it! Only I use ControlGetFocus in stead of ControlFocus, but it works like a charm :):(

Edited by JamesNL
Link to comment
Share on other sites

  • Moderators

Can you tell us what you actually want to accomplish with the script you provided, it seems you have a question about one thing, and provided a script on another?

It's hard to give an example of what we would do with at least a recreation script of the current problem if you know what I mean.

In the StripTags($invoer) function, are you wanting only to allow regular letters / numbers? I ask this because of the $denyString.

Edit:

Just read your edit:

Ok, good, now disregard the 1st 2 lines there, on to the serial number question.

Edit2:

ControlGetFocus forces focus on a control, I thought you only wanted to do something "If" a control had focus?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Can you tell us what you actually want to accomplish with the script you provided, it seems you have a question about one thing, and provided a script on another?

It's hard to give an example of what we would do with at least a recreation script of the current problem if you know what I mean.

I know what you mean, the attached script is a part of a larger script I'm working on, and I only want to check for the serial number when the field is focussed.

In the StripTags($invoer) function, are you wanting only to allow regular letters / numbers? I ask this because of the $denyString.

Indeed, that's what I want

Edit:

Just read your edit:

Ok, good, now disregard the 1st 2 lines there, on to the serial number question.

Edit2:

ControlGetFocus forces focus on a control, I thought you only wanted to do something "If" a control had focus?

Now you're confused, ControlFocus focusses a control, ControlGetFocus returns the focussed control :)
Link to comment
Share on other sites

  • Moderators

Indeed, that's what I want

Try this:
MsgBox(0, 'Test', StripTags("`I~!@#$%^&*()a_+=m[]}{\T';:e|/s.,?t>i<áàänâgëéèêîïí1ìöôó2òúùûü3ÿý"))


Func StripTags($invoer)
    Local $storeinfo = ''
    $invoer = StringSplit($invoer, '', 1)
    
    For $i = 1 To UBound($invoer) - 1
        If StringIsASCII($invoer[$i]) And StringIsAlNum($invoer[$i]) Then _
                $storeinfo = $storeinfo & $invoer[$i]
    Next
    Return $storeinfo
EndFunc
I'll look at the rest later this evening, going to be getting ready for my sons bday party in a few minutes and can't concentrate with all the kids in the house at the moment.

Now you're confused, ControlFocus focusses a control, ControlGetFocus returns the focussed control :)

I'll chalk that up to the hangover, but yep!!

Edit:

The more I thought about the above function in the 2 minutes of quiet in my home, the more I realized you just needed StringRegExpReplace:

MsgBox(0, 'Test', StripTags("`I~!@#$%^&*()a_+=m[]}{\T';:e|/s.,?t>i<áàänâgëéèêîïí1ìöôó2òúùûü3ÿý"))

Func StripTags($invoer)
    Return StringRegExpReplace($invoer, '[^a-zA-Z0-9]', '')
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Try this:

MsgBox(0, 'Test', StripTags("`I~!@#$%^&*()a_+=m[]}{\T';:e|/s.,?t>i<áàänâgëéèêîïí1ìöôó2òúùûü3ÿý"))
Func StripTags($invoer)
    Local $storeinfo = ''
    $invoer = StringSplit($invoer, '', 1)
    
    For $i = 1 To UBound($invoer) - 1
        If StringIsASCII($invoer[$i]) And StringIsAlNum($invoer[$i]) Then _
                $storeinfo = $storeinfo & $invoer[$i]
    Next
    Return $storeinfo
EndFunc
I'll look at the rest later this evening, going to be getting ready for my sons bday party in a few minutes and can't concentrate with all the kids in the house at the moment.I'll chalk that up to the hangover, but yep!!

Edit:

The more I thought about the above function in the 2 minutes of quiet in my home, the more I realized you just needed StringRegExpReplace:

MsgBox(0, 'Test', StripTags("`I~!@#$%^&*()a_+=m[]}{\T';:e|/s.,?t>i<áàänâgëéèêîïí1ìöôó2òúùûü3ÿý"))

Func StripTags($invoer)
    Return StringRegExpReplace($invoer, '[^a-zA-Z0-9]', '')
EndFunc
Thanks for your effort, Smoke_N, but the dashed should remain too, do you know how I can keep them with this RegExp?

By the way, congrats with your son :)

Link to comment
Share on other sites

  • Moderators

Thanks for your effort, Smoke_N, but the dashed should remain too, do you know how I can keep them with this RegExp?

By the way, congrats with your son :(

Thanks JamesNL and Valuater, it was a huge success (They successfully gave me a splitting headache :) )

By "dash" do you mean "hyphen"?

MsgBox(0, 'Test', StripTags("`I~!@#$%^&*()-a_+=m-[]}{\T';:e|/s.,?t>i<áàänâgëéèêîïí-1ìöôó-2òúùûü-3ÿý"))

Func StripTags($invoer)
    Return StringRegExpReplace($invoer, '[^a-zA-Z0-9-]', '')
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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