Jump to content

Events


Recommended Posts

Hello, i was wondering if and how it is possible to attach multiple events to 1 ctrl

for example i have a list with items in it, if i left click i want to execute function 1, if i right click i want to execute function 2

i have tried with or without GUIOnEventMode = 1 but i am unable to get such thing working it seems (been digging through the manual, but i cant really figure out how to do this) :)

Link to comment
Share on other sites

Hi, I tried a dodgey aproach to what you asked about it works sorta ... :)

The buggiest thing is though , if either one on the lines is highlighted and you left or right click in the list box not on a line then the event will be tripped off. It still gives the correct event and the corect focused line though..

#include <GuiConstants.au3>
#include <constants.au3>

Opt("GUIOnEventMode", 1)
$Gui = GUICreate('Test 2 functions on 1 control', 320, 220, @DesktopWidth - 340, -1, -1, $WS_EX_TOPMOST)
$mylist = GUICtrlCreateList ("", 10,10,300,200)
GUICtrlSetData(-1,'Pretend this is a control|Pretend this is a control as well')
GuiSetOnEvent($GUI_EVENT_PRIMARYDOWN, 'Event1')
GuiSetOnEvent($GUI_EVENT_SECONDARYDOWN, 'Event2')
GuiSetOnEvent($GUI_EVENT_CLOSE, 'Close')
GUISetState ()

While 1 
    Sleep(10)
Wend

Func Event1()
    $ci = GUIGetCursorInfo($Gui)
    If $ci[4] = $mylist Then
        GuiSetOnEvent($GUI_EVENT_SECONDARYDOWN, '')
        MsgBox(0,'Event1', 'Left Mouse Down Reads:' & @LF & GUICtrlRead($mylist))
        GuiSetOnEvent($GUI_EVENT_SECONDARYDOWN, 'Event2')
    EndIf
EndFunc

Func Event2()
    $ci = GUIGetCursorInfo($Gui)
    If $ci[4] = $mylist Then    
        GuiSetOnEvent($GUI_EVENT_PRIMARYDOWN, '')
        MouseClick("primary")
        MsgBox(0,'Event2','Right Mouse Down Reads:' & @LF & GUICtrlRead($mylist))
        GuiSetOnEvent($GUI_EVENT_PRIMARYDOWN, 'Event1')
    EndIf
EndFunc

Func Close()
    Exit
EndFunc

Who says cheats don't prosper? Buwahahahaha.

(used rightclick to leftclick a focus on a line while disabling/enabling the opposing event).

I spose that's just thinking outside the box really or is it more like bad scripting. :D

I think it's more the latter of 2 ...

Cheers.

Link to comment
Share on other sites

Hehe well actually i had also something like you and with the same result: if you click anywhere in the listbox it triggers also the event :)

but i was wondering if there wasnt a cleaner way ... (maybe feature request? )

Also for example i had the same problem with a menu i attached to the tray icon: i wanted a window to get focus if i double click the trayicon (i created a toolbox, so no task bar thing ) and if i rightclick a menu where you can choose for example exit or help

but the same applies here: if i double click i also get the menu (even though the focus event is also triggered) and strange thing is that with the default menu it does work. (so i have an application with default menu where rightclick shows the menu and left double click brings it in focus)

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...