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: 766
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

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).
Let>ME=%Script%

Running: 15.0.19b
version history

User avatar
Grovkillen
Automation Wizard
Posts: 766
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, 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.19b
version history

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