[Fixed] PopupMenu> click outside = close the menu (result = -1)

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 998
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

[Fixed] PopupMenu> click outside = close the menu (result = -1)

Post by Grovkillen » Tue Sep 21, 2021 6:14 pm

It would be nice if we could close the menu by simply clicking outside of it. It's not 100% fool proof the way it's done now (you have to click the icon again to close it without selecting any option).
Last edited by Grovkillen on Fri Mar 08, 2024 2:48 pm, edited 1 time in total.
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 998
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: PopupMenu> click outside = close the menu (result = -1)

Post by Grovkillen » Fri Sep 24, 2021 6:04 am

I managed to work around this limitation, here's how:

Code: Select all


Let>MENU_CLICKED=False
Let>MENU_CLICKED_TIME=0
Let>MENU_CLICKED_TIMEOUT=10*1000
Let>HIDDEN_POSITION=-100000
Let>HIDDEN_SIZE=1

IfNotFileExists>%SCRIPT_DIR%\mainicon.ico
  ExportData>MAINICON.ICO_DATA,%SCRIPT_DIR%\mainicon.ico
Endif>

OnEvent>CUSTOM,MONITOR_TRAY_MENU,MENU_OPEN_TOO_LONG,CLOSE_TRAY_MENU
GoSub>SETUP_THE_TRAY_ICON_AND_MENU

Label>mainLoopStart
Wait>0.25
Goto>mainLoopStart

SRT>SETUP_THE_TRAY_ICON_AND_MENU
  IfNotFileExists>%SCRIPT_DIR%\mainicon.ico
    ExportData>MAINICON.ICO_DATA,%SCRIPT_DIR%\mainicon.ico
  Endif>
  AddTrayIcon>%SCRIPT_DIR%\mainicon.ico,TrayIcon,MENU CLOSE TEST
  AddTrayHandler>TrayIcon,OnClick,OPEN_TRAY_MENU
END>SETUP_THE_TRAY_ICON_AND_MENU

SRT>OPEN_TRAY_MENU
  Timer>MENU_CLICKED_TIME
  Let>MENU_CLICKED=True
  Let>MENU_LIST=Open;Exit
  Separate>MENU_LIST,;,TRAY_MENU_SELECTIONS
  GetCursorPos>MENU_X,MENU_Y
  PopupMenu>MENU_X,MENU_Y,MENU_LIST,TREY_MENU_SELECTED
  Add>TREY_MENU_SELECTED,1
  Let>MENU_CLICKED=False
  IfNot>TREY_MENU_SELECTED=0
    Let>TRAY_MENU_ACTION=TRAY_MENU_SELECTIONS_%TREY_MENU_SELECTED%
    LowerCase>TRAY_MENU_ACTION,TRAY_MENU_ACTION
    GoSub>TRAY_MENU_ACTION_%TRAY_MENU_ACTION%
  Endif>
END>OPEN_TRAY_MENU

SRT>MONITOR_TRAY_MENU
  If>MENU_CLICKED=True
    Timer>MENU_CLICKED_TIME_now
    Let>MENU_CLICKED_TIME_diff=MENU_CLICKED_TIME_now-MENU_CLICKED_TIME
    If>MENU_CLICKED_TIME_diff>MENU_CLICKED_TIMEOUT
      Let>MENU_OPEN_TOO_LONG=True
    Endif>
  Endif>
END>MONITOR_TRAY_MENU

SRT>CLOSE_TRAY_MENU
  GoSub>FAKE_MESSAGE
  Let>MENU_CLICKED=False
  Let>MENU_OPEN_TOO_LONG=False
END>CLOSE_TRAY_MENU

SRT>TRAY_MENU_ACTION_exit
  DelTrayIcon>TrayIcon
  Exit>
END>TRAY_MENU_ACTION_exit

SRT>TRAY_MENU_ACTION_open
Message>hello!
END>TRAY_MENU_ACTION_open

SRT>FAKE_MESSAGE
  Let>DEFAULT_MSG_XPOS=MSG_XPOS
  Let>DEFAULT_MSG_YPOS=MSG_YPOS
  Let>DEFAULT_MSG_HEIGHT=MSG_HEIGHT
  Let>DEFAULT_MSG_WIDTH=MSG_WIDTH
  Let>MSG_XPOS=HIDDEN_POSITION
  Let>MSG_YPOS=HIDDEN_POSITION
  Let>MSG_HEIGHT=HIDDEN_SIZE
  Let>MSG_WIDTH=HIDDEN_SIZE
  Message>
  Let>MSG_XPOS=DEFAULT_MSG_XPOS
  Let>MSG_YPOS=DEFAULT_MSG_YPOS
  Let>MSG_HEIGHT=DEFAULT_MSG_HEIGHT
  Let>MSG_WIDTH=DEFAULT_MSG_WIDTH
END>FAKE_MESSAGE
/*
MAINICON.ICO_DATA:
THIS NEED TO BE IMPORTED FROM THE "oldicons/mainicon.ico" FOUND IN THE MS INSTALL PATH
*/
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 998
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: PopupMenu> click outside = close the menu (result = -1)

Post by Grovkillen » Fri Mar 08, 2024 2:41 pm

This is now fixed (tested in 15.0.24)

Code: Select all

Let>TEMP_popup_data=Hello;Yo!
Separate>TEMP_popup_data,;,SELECTION
GetCursorPos>MENU_X,MENU_Y
PopupMenu>MENU_X,MENU_Y,TEMP_popup_data,POPUP_CLICKED
If>POPUP_CLICKED>-1
  Add>POPUP_CLICKED,1
  PutClipBoard>SELECTION_%POPUP_CLICKED%
Else>
**BREAKPOINT**
Endif>
Let>ME=%Script%

Running: 15.0.24
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts