Jump to content

Ampersand Shortcut


Recommended Posts

My script requires there to be an ampersand (&) within a list, which when selected, the name of the item is then pulled into a label. The issue being, in the list it displays as "Sweat&Sour", but in the label, it displays as "SweatSour" due to the ampersand triggering the Alt-shortcut. Is there anyway to prevent this from happening, besides doubling up the ampersand? As it would then display as "Sweat&&Sour" in the list, but "Sweat&Sour" in the input.

#include <GUIConstantsEx.au3>

GUICreate("Ampersand Shortcut", 200, 200)
$list = GUICtrlCreateList("", 10, 10, 180, 90)
GUICtrlSetData(-1, "Sweat&Sour|Sweat&&Sour")
$label = GUICtrlCreateLabel("", 25, 125, 150, 20)
GUISetState()

Do
    $msg = GUIGetMsg()
    If $msg = $list Then GUICtrlSetData($label, GUICtrlRead($list))
Until $msg = $GUI_EVENT_CLOSE
Link to comment
Share on other sites

Double up the ampersand when you read it from the list:

#include <GUIConstantsEx.au3>

GUICreate("Ampersand Shortcut", 200, 200)
$list = GUICtrlCreateList("", 10, 10, 180, 90)
GUICtrlSetData(-1, "Sweet&Sour|Thing|Yes & No")
$label = GUICtrlCreateLabel("", 25, 125, 150, 20)
GUISetState()

Do
    $msg = GUIGetMsg()
    If $msg = $list Then GUICtrlSetData($label, StringReplace(GUICtrlRead($list), "&", "&&"))
Until $msg = $GUI_EVENT_CLOSE
Link to comment
Share on other sites

There is a style called SS_NOPREFIX to suppress that ;)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

GUICreate("Ampersand Shortcut", 200, 200)
$list = GUICtrlCreateList("", 10, 10, 180, 90)
GUICtrlSetData(-1, "Sweat&Sour|Sweat&&Sour")
$label = GUICtrlCreateLabel("", 25, 125, 150, 20, $SS_NOPREFIX)
GUISetState()

Do
    $msg = GUIGetMsg()
    If $msg = $list Then GUICtrlSetData($label, GUICtrlRead($list))
Until $msg = $GUI_EVENT_CLOSE

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...