convert a single ascii character to unicode underscore

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

convert a single ascii character to unicode underscore

23 Aug 2017, 10:00

Hi,
I need a simple function or method to convert a single character, for example "S", to
be a Unicode underscored S.
MsgBox, 4096,, S underscored is: S̲

There is a web site that does this using JavaScript: https://thejh.net/misc/unicode-underline

Thanks
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 10:34

Try this:

Code: Select all

Loop, 26
    msg .= UnderscoreLetter(Chr(A_Index+64)) " "
msg .= "`n"
Loop, 26
    msg .= UnderscoreLetter(Chr(A_Index+96)) " "
MsgBox, %msg%

MsgBox, % "S underscored is: " UnderscoreLetter("S")
ExitApp



;-------------------------------------------------------------------------------
UnderscoreLetter(Letter) { ; return unicode letter with underscore
;-------------------------------------------------------------------------------
    Return, Letter Chr(0x0332)
}
I hope that helps.

Edit: renamed "convert" to "UnderscoreLetter"
Last edited by wolf_II on 23 Aug 2017, 10:53, edited 2 times in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 10:43

This is great thanks for sharing:

Code: Select all

q:: ;underline text
vText := "hello " JEE_StrUnderline("world") ", " JEE_StrUnderline("hello") " world"
MsgBox, % vText
return

JEE_StrUnderline(vText)
{
	return RegExReplace(vText, ".", "$0" Chr(818)) ;COMBINING LOW LINE
}
[EDIT:] Unfortunately not so good, the underlines vary in position, still a nice idea though:

Code: Select all

w::
vText := JEE_StrUnderline("Plan for AutoHotkey") "`r`n`r`n" JEE_StrUnderline("Day 1") "`r`n`r`n" "do stuff" "`r`n`r`n" JEE_StrUnderline("Day 2") "`r`n`r`n" "do stuff"
MsgBox, % vText
MsgBox, % Format("{:U}", vText)
return
Last edited by jeeswg on 23 Aug 2017, 11:31, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 11:12

@ jeeswg, maybe try something with Chr(0x035F).
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 11:32

Nice idea Helgef, it still doesn't work too great though:

Although I can skip the spaces, it also seems to handle numbers differently.

Code: Select all

vText := JEE_StrUnderline("Plan for AutoHotkey") "`r`n`r`n" JEE_StrUnderline("Day 1") "`r`n`r`n" "do stuff" "`r`n`r`n" JEE_StrUnderline("Day 2") "`r`n`r`n" "do stuff"
vText2 := JEE_StrUnderline2("Plan for AutoHotkey") "`r`n`r`n" JEE_StrUnderline2("Day 1") "`r`n`r`n" "do stuff" "`r`n`r`n" JEE_StrUnderline2("Day 2") "`r`n`r`n" "do stuff"
MsgBox, % vText
MsgBox, % vText2
MsgBox, % Format("{:U}", vText)
MsgBox, % Format("{:U}", vText2)
return

JEE_StrUnderline(vText)
{
	return RegExReplace(vText, ".", "$0" Chr(818)) ;COMBINING LOW LINE
}

JEE_StrUnderline2(vText)
{
	return RegExReplace(vText, ".", "$0" Chr(863)) ;COMBINING DOUBLE MACRON BELOW
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 11:50

Wow, wolf_II, this is great. So quick and simple.
Thanks a lot to both of you.

This solves a problem I have seen many posts about on getting the underscore to appear on GUI buttons in W7(-)
No more, Send, {Alt} or having to press [Alt] to see the shortcut underscores. Alt makes a lot of trouble, like
locking the PC until you click the form, or actually use one the alt shortcut keys.

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

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

Do you think there would be any conflict using this for W7 Ultimate, W8, W8.1 W10 etc., which do show the
underscore automatically.
I could conditionalize it to older OS systems if necessary. How would I say "equal to or earlier than W7 plain"
ie: XP Vista, W7, W2000, W2003, and Not W7 Ultimate, W8, W8.1 W10+++ which already do show the underscores?

Thanks a million!
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 11:54

Sorry if this is OT Visioneer.
@ jeeswg, it seems the space need no underline, and triming the trailing one also improves. But still not perfect.
rtrim(RegExReplace(vText, "[^ ]", "$0" Chr(863)),Chr(863)).
It seems there needs to be special treatment for space followed by captial letter. Probably others too.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 11:58

Wow, wolf_II, this is great. So quick and simple.
Thanks a lot to both of you.

This solves a problem I have seen many posts about on getting the underscore to appear on GUI buttons in W7(-)
No more, Send, {Alt} or having to press [Alt] to see the shortcut underscores. Alt makes a lot of trouble, like
locking the PC until you click the form, or actually use one the alt shortcut keys.

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

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

Do you think there would be any conflict using this for W7 Ultimate, W8, W8.1 W10 etc., which do show the
underscore automatically.
I could conditionalize it to older OS systems if necessary. How would I say "equal to or earlier than W7 plain"
ie: XP Vista, W7, W2000, W2003, and Not W7 Ultimate, W8, W8.1 W10+++ which already do show the underscores?

Thanks a million!

PS: Any possibility of incorporating BOLDness into result. The underscore letter I get is a little feint, unless I use a larger
font size.
Gui, Font, s14 cblack, Verdana ;is a little feint.
Gui, Font, s16 cblack, Verdana ; is fine
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 11:59

see A_OSVersion
I can't test the correct formula for the If statement, as I have not all these OS available to me, sorry.
try If A_OSVersion in WIN_VISTA,WIN_7,WIN_2000,WIN_2003

Re: boldness - I have no idea.

Edit: fixed typo
Last edited by wolf_II on 23 Aug 2017, 12:15, edited 1 time in total.
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 12:12

Helgef wrote:Sorry if this is OT Visioneer.
@ jeeswg, it seems the space need no underline, and triming the trailing one also improves. But still not perfect.
rtrim(RegExReplace(vText, "[^ ]", "$0" Chr(863)),Chr(863)).
It seems there needs to be special treatment for space followed by captial letter. Probably others too.
What if you make the preceding character the same each time (zero width space) so the underline is always in the same position?

Code: Select all

Return Chr(0x200B) Chr(0x035F) RTrim(RegExReplace(vText, ".", "$0" Chr(0x200B) Chr(0x035F)), Chr(0x200B) Chr(0x035F))
Edit: Added the Chr(0x200B) Chr(0x035F) to the begining because it looked like it didn't start early enough.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 12:16

Nice one Nightwolf85 :thumbup:
Edit: Even better!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 12:40

Very nice Nightwolf85. Here is some sample text for testing:

Code: Select all

;818 = 0x332 ;863 = 0x35F
q::
vText := "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9"
MsgBox, % RegExReplace(vText, "[^ ]", "$0" Chr(818)) ;COMBINING LOW LINE
MsgBox, % RegExReplace(vText, "[^ ]", "$0" Chr(863)) ;COMBINING DOUBLE MACRON BELOW
MsgBox, % Chr(0x200B) Chr(0x035F) RTrim(RegExReplace(vText, ".", "$0" Chr(0x200B) Chr(0x035F)), Chr(0x200B) Chr(0x035F))
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 13:03

Visioneer, regarding your gui issues, have you considered using something like this, it might give you more consistent results.

[spoiler2=off topic]now we need a function which takes a text and an optional array of words to underline. If omtted, the whole text is underlined. Can we do strike? :angel:[/spoiler2]
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 13:28

I have been using the underscore S etc with W8.1 by pasting in the S̲ directly into the button text and it has been working nicely. So I do not
think it could any easier or more consistent than wolf_II's simple function whatever the system. I will do a simple conditional with it, although
I don't think it would matter. I only need the first, one single underlined character for my purposes. I will refer this post to a few other posts
on this Gui button topic. I have over a hundred buttons I will be updating.

Thanks to all.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 14:00

I added the feature of choosing the character to be underscored:

Code: Select all

Test := "Underscore"
Loop, % StrLen(Test)
    msg .= Underscore(Test, A_Index) "`n"
MsgBox, %msg%
ExitApp


;-------------------------------------------------------------------------------
Underscore(String, Pos) { ; return String with character in Pos underscored
;-------------------------------------------------------------------------------
    Return, SubStr(String, 1, Pos-1)
          . SubStr(String, Pos, 1) Chr(0x0332)
          . SubStr(String, Pos+1)
}
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 14:18

another one:

Code: Select all

MsgBox, % Amper("Under&score")
ExitApp



;-------------------------------------------------------------------------------
Amper(String) { ; return String with the ampersanded character underscored
;-------------------------------------------------------------------------------
    Return, SubStr(String, 1, (Pos := InStr(String, "&")) - 1)
          . SubStr(String, Pos+1, 1) Chr(0x0332)
          . SubStr(String, Pos+2)
}
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: convert a single ascii character to unicode underscore

23 Aug 2017, 23:14

Sorry I misled you guys about this underscore thing not being involved in Win8+(plus). I was misled myself, (on this forum). It turns out that all windows
OSs have the "problem" er "feature".
I will definitely use this function for my main mission critical forms. About 20 buttons. But those other hundreds? A lot of work, and it is a tiny bit unsightly.

I will now look into how to auto set/unset the registry,
1.Run Registry Editor and go to HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Preference
2.Now create or modify a String Value (REG_SZ) called On and set its value to 1
This part is easy with AHK, (but that requires a reboot I read).
Is there a way to do a reset without actually rebooting?
That would probably be more consistent across OSs.
Or
See if I could macro auto go into control panel,
Control panel -> ease of access center -> make the keyboard easier to use -> underline keyboard shortcuts and access keys.
and make the changes (only if needed) , with an option to revert "on exit" or by some "on demand" menu choice.
Probably a version nightmare.

I have long thought there should be a way to effect certain system settings in memory, that go away on demand or exit.

Thanks, sorry again. :(
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: convert a single ascii character to unicode underscore

25 Aug 2017, 14:14

The underscore is a little uneven, especially in larger buttons. Great for my purposes however. I am thinking that some fonts/sizes/boldness will be better than
others. Maybe there should be a font made especially for this wolf_II and jeewg techniques.

I have been successful in toggling the "alt shortcuts" control panel setting with a hotkey, so I will use the function as the start off for a few important GUI forms.
The conditional I use in the function is the value read in the registry shown above. If it Is 1, just return "Letter".

Thanks again.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest, Bing [Bot], peter_ahk and 318 guests