simple Edit control with mask

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
David4
Posts: 27
Joined: 12 Jul 2016, 14:28

simple Edit control with mask

Post by David4 » 29 Jun 2022, 15:06

I'm sure, there's already something but I can't find it:
gui,add,edit,vMyEdit gMyformat

a subroutine, that reliable and full editable formats MyEdit like "##.##.####" , "##/##" or similar. It should use only one Edit-field and run with AHK 1.0.x
User should only enter or delete the numbers, not the special characters.

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: simple Edit control with mask

Post by mikeyww » 29 Jun 2022, 17:28

Code: Select all

If !A_IsAdmin && !(DllCall("GetCommandLine", "str") ~= " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
} Else Gui, Font, s10
Gui, Add, Edit, w240 vstr gCheck
Gui, Show,, Number
Return
Check:
BlockInput, On
Gui, Submit, NoHide
Send % str ~= "[^./0-9]" ? "`b" : ""
BlockInput, Off
Return

gregster
Posts: 8988
Joined: 30 Sep 2013, 06:48

Re: simple Edit control with mask

Post by gregster » 29 Jun 2022, 18:22

I guess at least Try won't be available in AHK 1.0.x; it seems some people are still using Chris' last version 1.0.48.05 from 2009. Other things might need to be changed to run with that version, like ~= which was introduced in v1.0.90 (which is not considered a version of classic "Chris Mallet"v1.0.x, afaik, but already of "AHK_L(exikos)").
It's perhaps time to learn something new and move on, most people don't remember the specifics of 1.0.x, or don't want to - and to get support for it won't get easier, David4. Or was it just a typo?

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: simple Edit control with mask

Post by mikeyww » 29 Jun 2022, 18:45

Thanks, gregster, and sorry I did not pay any attention to the version!

David4
Posts: 27
Joined: 12 Jul 2016, 14:28

Re: simple Edit control with mask

Post by David4 » 30 Jun 2022, 13:12

gregster wrote:
29 Jun 2022, 18:22
I guess at least Try won't be available in AHK 1.0.x; it seems some people are still using Chris' last version 1.0.48.05 from 2009. Other things might need to be changed to run with that version, like ~= which was introduced in v1.0.90 (which is not considered a version of classic "Chris Mallet"v1.0.x, afaik, but already of "AHK_L(exikos)").
Yes. I could workaround that, but the code above seems to have no relation to my question...
Nevertheless I can't find the meaning of `b in the docu. Until now I had not enough reasons to switch the version. Only for testing purposes. My scripts should run under all versions since 1.0.48. Thank you.

gregster
Posts: 8988
Joined: 30 Sep 2013, 06:48

Re: simple Edit control with mask

Post by gregster » 30 Jun 2022, 13:16

Probably a backspace (as an escape sequence): https://www.autohotkey.com/docs/misc/EscapeChar.htm
No idea if this works in 1.0.48, but ~= as a shortcut for RegEx surely won't.

David4
Posts: 27
Joined: 12 Jul 2016, 14:28

Re: simple Edit control with mask

Post by David4 » 30 Jun 2022, 13:23

gregster wrote:
30 Jun 2022, 13:16
Probably a backspace (as an escape sequence): https://www.autohotkey.com/docs/misc/EscapeChar.htm
Bingo, thanks. I only searched in RegEx-Topics.

Nobody with an elegant solution for the "##/##"-mask - question?

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: simple Edit control with mask

Post by mikeyww » 30 Jun 2022, 13:26

You tested my script?

Code: Select all

If !A_IsAdmin && !(DllCall("GetCommandLine", "str") ~= " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
} Else Gui, Font, s10
Gui, Add, Edit, w240 vstr gCheck
Gui, Show,, Number
Return
Check:
BlockInput, On
Gui, Submit, NoHide
Send % RegExMatch(str, "[^./0-9]") ? "{BS}" : ""
BlockInput, Off
Return

David4
Posts: 27
Joined: 12 Jul 2016, 14:28

Re: simple Edit control with mask

Post by David4 » 30 Jun 2022, 13:32

mikeyww please stop flooding this topic, thanks.

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: simple Edit control with mask

Post by mikeyww » 30 Jun 2022, 13:41

OK, I shall do that. I replied because I believed that I had addressed your question, and you never indicated whether you tried the script, that's all. In my revision, I addressed any potential issue with ~= (OK, forgot the first one) as well as `b. Cheers.

User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: simple Edit control with mask

Post by AlphaBravo » 30 Jun 2022, 15:45

@mikeyww , thanks for being so polite.
@David4, it is recommended to upgrade to the latest ahk
I don't know about "elegant" but gets the job done for the most part.

Code: Select all

Gui, Add, Edit, w240 vstr gMask number
Gui, Show,, Number
Return
;---------------------------------------
Mask:
if DelKey
	return
Gui, Submit, NoHide
OnMessage(0x111, Func("Suppress"), 1)
str := StrReplace(str, ".")
str := RegExReplace(str, "^(\d\d)(?!\.)", "$1.")				; ##.
str := RegExReplace(str, "^\d\d\.\K(\d\d)(?!\.)", "$1.")		; ##.##.
str := RegExReplace(str, "^\d\d\.\d\d\.\K(\d\d\d\d).*$", "$1")	; ##.##.####
GuiControl,, str, % str
Send {End}
OnMessage(0x111, Func("Suppress"), 0)
Return
;---------------------------------------
#if getActiveEdit("str")
$BackSpace::
Gui, Submit, NoHide
if RegExMatch(str, "\.$")
	Send {Left}{BackSpace}
else
	Send {BackSpace}
return

Delete::
DelKey := true
Send {Delete}
DelKey := false
return
#if
;---------------------------------------
Suppress(wParam) {				; https://www.autohotkey.com/boards/viewtopic.php?t=57546#p243702
    if (wParam >> 16) = 0x300	; EN_CHANGE
        return 0				; Prevent default processing by returning a value.
}
;---------------------------------------
getActiveEdit(ctrlName){
	GuiControlGet, var, focusV
	return (var = ctrlName)
}

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: simple Edit control with mask

Post by flyingDman » 30 Jun 2022, 16:06

@mikeyww You could have ignored that request. IMHO requests like that do not belong on the forum.
@AlphaBravo Very nice (and above my pay grade!)!
14.3 & 1.3.7

gregster
Posts: 8988
Joined: 30 Sep 2013, 06:48

Re: simple Edit control with mask

Post by gregster » 30 Jun 2022, 18:18

I think that support for ancient 1.0.48 versions (dating back 13 years) shouldn't be taken for granted.
If you want such backwards compatibility, it's your own responsibility to keep up with the requirements.

A response like "mikeyww please stop flooding this topic, thanks", I would call "ziemlich frech" in german. I guess, David4 will understand that.
All helpers on these forums are dedicating their free time to help; antagonizing them is not a smart way to make use of their huge amount of experience and expertise.

Post Reply

Return to “Ask for Help (v1)”