How to avoid or disable windows beep/sound when GUI's edit/input field characters limit is reached

Put simple Tips and Tricks that are not entire Tutorials in this forum
sleep_is_my_friend
Posts: 30
Joined: 10 Feb 2022, 05:01

How to avoid or disable windows beep/sound when GUI's edit/input field characters limit is reached

Post by sleep_is_my_friend » 06 Mar 2022, 05:45

Hi! Based on the code by @da_boogey_man, I modified the code to set a characters limit for the Edit field by using the limit keyword:

Code: Select all

#SingleInstance Ignore

Gui, Add, Edit, x10 y10 w150 limit4 gGetCount vedtType
Gui, Add, Text, x10 y+10 w150 vtxtCount
Gui, Show, Center
Return

GetCount:
  GuiControlGet, myString,, edtType
  nowCount := StrLen(myString)
  GuiControl,, txtCount, %nowCount%/4
Return

ESC::
GuiClose:
  ExitApp
Return
, but each time I'd reach the 4 characters set by the limit the windows beep would trigger, which is really annoying to me. To not have to play the windows beep anymore, I came up with this solution:

Code: Select all

#SingleInstance Ignore
SetKeyDelay, -1, -1

Gui, Add, Edit, x10 y10 w150 gGetCount vedtType
Gui, Add, Text, x10 y+10 w150 vtxtCount
Gui, Show, Center
Return

GetCount:
  GuiControlGet, myString,, edtType
  nowCount := StrLen(myString)
  GuiControl,, txtCount, %nowCount%/4
  If nowCount > 4
	ControlSend, Edit1, {BackSpace}
Return

ESC::
GuiClose:
  ExitApp
Return
I'm sorry if this was posted before! I just thought this might be helpful to someone.

Return to “Tips and Tricks (v1)”