Page 1 of 1
long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 07:59
by PuzzledGreatly
I have this code to activate a different function depending upon whether a key press is short or long:
Code: Select all
q::
KeyWait, %A_ThisHotkey%, T0.75
errorlevel ? Function1() : Function(2)
return
The problem is that when the key press is long and I get an errorlevel I also hear a windows ding. How to avoid the ding? Is there a better approach to getting two results dependent upon the length of key press? Thanks.
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 08:03
by mikeyww
Yeah, fix your functions (which are not provided here)!
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 08:10
by PuzzledGreatly
Thanks Mikey, but if I send the same function I get nothing with the short key press but I get a ding with the long key press suggesting to me that it is not the function but the method:
Code: Select all
q::
KeyWait, %A_ThisHotkey%, T0.75
errorlevel ? Function(2) : Function(2) ;ding/no ding
return
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 08:56
by boiler
I'm not hearing a ding no matter how long I press the key with the following:
Code: Select all
q::
KeyWait, %A_ThisHotkey%, T0.75
errorlevel ? Function(1) : Function(2)
return
Function(n) {
ToolTip, % n
}
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 09:14
by PuzzledGreatly
Thanks boiler, I tried your code and got a ding. How long did you hold the key for?
Edit: I used this code:
Code: Select all
q::
KeyWait, %A_ThisHotkey%, T0.75
errorlevel ? Function(1) : Function(2)
return
Function(n) {
msgbox, 4096, OK, % n
}
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 09:23
by mikeyww
Is this the entire script? Are other scripts running at the same time?
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 09:29
by PuzzledGreatly
Thanks, Mikey, when I isolate the q hotkey I don't get a ding. But how can I track down what is causing the ding? I don't think it can be boiler's amended function with the msgbox. What kind of things should I be looking for? My whole script is over 1000 lines long.
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 09:35
by mikeyww
You can isolate the problem within a few minutes, by removing half of the remaining script, retesting, and repeating the process until the sound disappears. You will then have pinpointed the problem.
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 09:45
by PuzzledGreatly
Thanks, Mikey, but my script doesn't lend itself to that approach. I'm going to sleep on it and in the morning look at the functions I call in detail
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 10:07
by boiler
PuzzledGreatly wrote: ↑
Thanks boiler, I tried your code and got a ding. How long did you hold the key for?
I can hold it for a very long time (10 seconds or more), and still no ding. I tried your script with the MsgBox as well and it's the same thing.
I wonder if it might be this...Perhaps certain ding sounds are "empty" on some systems but not on others. For example, I don't get a ding when I produce a MsgBox with the question mark icon like below, but I thought I remember it producing a ding on previous versions of Windows I had. Do you get a ding with the following?
Code: Select all
MsgBox, 32, Ding?, Does this MsgBox produce a ding?
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 10:21
by mikeyww
Sounds can be altered if needed:
C:\Windows\System32\rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,2
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 18:12
by PuzzledGreatly
Thanks, boiler, I don't get a sound with your msgbox code. With the following script I get a ding with any letter key except q. Do you?
Code: Select all
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
#Persistent
#SingleInstance force
Gui, New, -dpiscale -caption border, Ding Tester
Gui, font, s20 bold
Gui, add, text, w600 center, Do you hear a ding when you press q?
Gui, add, text, w600 center, Do you hear a ding pressing other keys?
Gui, show, xcenter y200
return
q:: MsgBox, 32, Ding?, Does this MsgBox produce a ding?
esc:: exitapp
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 18:58
by boiler
PuzzledGreatly wrote: ↑
With the following script I get a ding with any letter key except q. Do you?
Yes, same here. Ding with any letter key except q.
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 19:04
by mikeyww
The "question" MsgBox designated by option 32 does not make a sound, by default. At least that is the case on my computer. There is a Windows "Utopia Question" WAV file that was used on Windows 7. I do not know whether Windows 10 changed this-- did change some of the sounds-- and also do not know whether the silence of the MsgBox is "intended" by the developer, but it is silent on my system.
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 19:33
by PuzzledGreatly
Thanks for the info, Mikey. This seems to be the solution on my PC. No Ding:
Code: Select all
q::
keywait q
a_timeSinceThisHotkey > 750 ? function1() : function2()
return
function1() {
msgbox, function1
}
function2() {
msgbox, function 2
}
Re: long/short keypress - avoid Windows ding?
Posted: 08 May 2021, 20:37
by mikeyww
Sure, if you provide no options, there will be no sound.
Re: long/short keypress - avoid Windows ding?
Posted: 10 May 2021, 07:51
by PuzzledGreatly
But the original method I posted using errorlevel did produce a ding with my machine, hence this thread.
Re: long/short keypress - avoid Windows ding?
Posted: 10 May 2021, 08:10
by mikeyww
You get a ding because that is what happens when you show a GUI and press a key. Demonstration is below.
Code: Select all
Gui, Add, Text, TEST
Gui, Show, w300, Test
This GUI cannot accept a key, so it plays a nice ding for you to notify you about that.
When you have a hotkey assigned, the hotkey routine will run instead. If your hotkey routine does not play a ding, then you will not hear any. If your hotkey routine is designed to play a ding, such as a MsgBox with an option for a ding sound, then you will hear it.
Re: long/short keypress - avoid Windows ding?
Posted: 13 May 2021, 07:56
by PuzzledGreatly
Mikey, I think your last post was not helpful and irrelevant. The point is that the method used to assess the long key press using errorlevel gave a ding but that using A_timeSinceThisHotkey did not. That's it.
Re: long/short keypress - avoid Windows ding?
Posted: 13 May 2021, 08:07
by mikeyww
Sorry if I missed the point. I was actually working with the script that you posted in explaining the exact findings, so I believed that I had completely explained your experience. It looks like I didn't!