Page 1 of 1

Ampersand in Gui,Add,Button fails to underline character

Posted: 30 Dec 2014, 15:46
by JoeWinograd
W7/64-bit
Version v1.1.14.03

With the Gui,Add,Button statement, an ampersand in front of a character in the button name is supposed to show an underline, indicating that Alt-TheUnderlinedCharacter will invoke the button (same as the button being clicked). However, the underline does not appear (although Alt-ThatCharacter does work). For example, this code will NOT show "F" underlined in the first button or "S" underlined in the second button (but Alt-F and Alt-S work):

Code: Select all

Gui,Add,Button,Default,&First
Gui,Add,Button,,&Second
Gui,Show,,ampersand underlining bug
Return

ButtonFirst:
MsgBox,4096,debug,first clicked
ExitApp

ButtonSecond:
MsgBox,4096,debug,second clicked
ExitApp

GuiClose:
GuiEscape:
ExitApp
A workaround is to send the Alt key after Gui,Show. In other words, this statement...

Send {Alt}

...placed right after the Gui,Show statement in the code above will cause the underlines on "F" and "S" to appear. Regards, Joe

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 30 Dec 2014, 15:52
by guest3456
this is not a bug afaik, this is standard Windows behavior for all Windows apps

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 30 Dec 2014, 16:19
by JoeWinograd
I don't know. You may be right that this is standard Windows behavior, but I can say for sure that Microsoft itself (at least in some cases) puts the underlines on the characters in buttons. For example, here's a typical MS installation dialog with two buttons, both containing the underline for the Alt-character (on the "I" and "u"):

Image

I did not hit the Alt key to get the underlines - they were there when the dialog came up. Regards, Joe

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 30 Dec 2014, 16:22
by Guest
It is a setting, you can change it, see http://ahkscript.org/boards/viewtopic.p ... =Ampersand

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 30 Dec 2014, 17:11
by JoeWinograd
But on the same system with the same setting, the AHK program does not show the underlines, while the MS program does. If the behavior is based on such a setting, I would expect both programs to behave the same - either both show it or both do not show it.

I reported this because I thought it was a bug, but if it's not, that's fine. I'm good with having my AHK script send the Alt key to activate the underlines for the user. Regards, Joe

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 30 Dec 2014, 18:39
by TAC109
On win 7, Control panel -> ease of access center -> make the keyboard easier to use -> underline keyboard shortcuts and access keys.

Works for me

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 30 Dec 2014, 19:02
by lexikos
JoeWinograd wrote:You may be right that this is standard Windows behavior, but I can say for sure that Microsoft itself (at least in some cases) puts the underlines on the characters in buttons.
It's been my observation that Office is one of the worst offenders for not following the standard Windows behaviour in various cases. Office and Windows are developed by separate teams; that both teams are employed by Microsoft doesn't seem to count for much.

Try other programs, or parts of Windows. For instance, the Screen Resolution control panel in Windows 7 doesn't show underlines until I press Alt.

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 31 Dec 2014, 00:38
by JoeWinograd
> On win 7, Control panel -> ease of access center -> make the keyboard easier to use -> underline keyboard shortcuts and access keys.

Yes, that works, but these are programs that I'm distributing to end-users. I don't want to ask them to go through that procedure. I'm fine with putting the Send {Alt} statement in the distributed programs.

> Office is one of the worst offenders for not following the standard Windows behaviour

Good point! And such irony.

> Try other programs

Tried several. It varies. In Adobe Acrobat, Adobe Reader, and IrfanView, the underlines in menus don't show up until you hit Alt. In Mozilla Firefox, Mozilla Thunderbird, and GIMP, the underlines in menus are always present.

In any case, I'm on board with saying it's a feature, not a bug. Thanks to everyone for your quick responses - much appreciated! Regards, Joe

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 31 Dec 2014, 04:29
by lexikos
Firefox, Thunderbird and GIMP are cross-platform programs which don't use the standard Windows controls.

Why are you working against this feature? Should the user not be expecting the underlines to be hidden when their system is set to behave that way? One could say that for any program to not respect the setting is a bug. That other programs don't conform to standard behaviour is no excuse.

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 31 Dec 2014, 12:08
by JoeWinograd
> Firefox, Thunderbird and GIMP are cross-platform programs which don't use the standard Windows controls.

Fair enough.

> Why are you working against this feature?

Because the two programs that I have up all day and spend the most time in are Firefox and Thunderbird, so I'm really used to seeing the underlines.

> Should the user not be expecting the underlines to be hidden when their system is set to behave that way?

Good point!

> One could say that for any program to not respect the setting is a bug. That other programs don't conform to standard behaviour is no excuse.

Yes, one could say that. You've convinced me. I won't send the Alt key and will leave it up to the keyboard setting in Control Panel>Ease of Access Center. Thanks, Joe

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 21 Aug 2017, 08:49
by Visioneer
1stly, I would not want to force the users make special changes.
2ndly, I have a form that is sometimes used to just take a quick view of a variable and is then immediately hotkey closed.
3rdly, I would very much like to have the underscore visible for ease of use and clarity sake.
4thly, I would not like to force the user to have to use their mouse at all ever.
5thly, Once [Alt] is pressed or Send {Alt} is used, it seems necessary to click the form with the mouse, as it becomes unresponsive
to my [Esc] to close, all my form hotkeys, (except the [Alt] ones) etc., until I physically click on the form.

So at the end of script section I want to use Send, {Alt} or some such, but then I want to add something to give control back to user,
like a simulated click, ControlClick, focus, activate, send lbutton, etc. I have tried many things, but I can't seem to get responsiveness
back without actually clicking on the form with the actual mouse, which I dislike the most of course.

Any ideas? I wonder what is actually happening to cause this to happen. All simulated clicks don't work?

Thanks

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 21 Aug 2017, 11:02
by obeeb
Why did you post this in a bug report from almost 3 years ago?!

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 21 Aug 2017, 17:07
by Visioneer
Most, even "lexikos", in this old thread were of the opinion that this issue was not a "bug" but a feature. I agree with him. I am simply looking for a workaround for something that was well defined in this old thread. I am also pointing out that this [Alt] situation goes beyond the initial underscore display, but applies to any pressing of the [Alt] key. Also it seems that many posts are no longer able to be replied to. Do you think I should repost it as a new request for help? I would like to bring this post along for the ride, as it had a top AHK programmer participating.

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 21 Aug 2017, 17:21
by obeeb
Visioneer wrote:Do you think I should repost it as a new request for help?
Yes, definitely do that. Start a new thread with a clear title and some code example(as small as possible) that clearly shows the problem and you will get help.

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 23 Aug 2017, 10:06
by Visioneer
Ok obeeb,
I have posted another help request that just asks for a simple conversion function.
Kindly do not minimalize, trivialize or distract it.
Thanks

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 23 Aug 2017, 10:31
by obeeb
Visioneer wrote:Kindly do not minimalize, trivialize or distract it.
You have nothing to worry about, from now on I will stay as far away as I can from your help requests.

Re: Ampersand in Gui,Add,Button fails to underline character

Posted: 23 Aug 2017, 18:43
by Visioneer
Many thanks to wolf_II for his quick and elegant solution.

I wrote:
Gui, Add, Button, gSearchers, % "&" . UnderscoreLetter("S") . "earchers"

wolf_II wrote:
UnderscoreLetter(Letter="") { Return, Letter Chr(0x0332) }

https://autohotkey.com/boards/viewtopic ... 50#p166650