[done] Get Event on ESC key in StringGadget

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

[done] Get Event on ESC key in StringGadget

Post by Kukulkan »

Hello,

I know about AddKeyboardShortcut() but I have issues using it to get ESC key in a given StringGadget.

At first, I'm inside a module and do not know a free menu event number for creation because users of my module might already use the same number. No #PB_Any available here :(

Also, I do not run the event loop (just a module to be used by others) and I use Bind functions to get events. But the StringGadget does not fire such keyboard events and I don't want to hook into the covering window because this will limit the user of my module (if he does the bind events for himself).

Also, it must be cross platform and Windows only tips would not really help.

Any idea?
Last edited by Kukulkan on Thu Jul 12, 2018 12:00 pm, edited 1 time in total.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Get Event on ESC key in StringGadget

Post by #NULL »

I used a hidden dummy window in a module to attach window timers so they are specific to my window and don't interfere with user menu values from other windows. Maybe that works for shortcuts too?
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Get Event on ESC key in StringGadget

Post by Kukulkan »

Hi,

no, looks like I can't route window events from the original users window to some dummy window. The events happen in the users window and there the menu events come in.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Get Event on ESC key in StringGadget

Post by kenmo »

Yes it's tricky if your module doesn't own the Window or the Gadget.

My two quick suggestions are:

1. Add a helper function for the user's code to define the event ID, then Bind that to #PB_Shortcut_Escape

2. Just choose a "random" event ID 0-64000 and hope the user code never conflicts :)
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Get Event on ESC key in StringGadget

Post by Kukulkan »

Thanks kenmo

I own my StringGadget but I don't own the Window or the event loop. Thus I work with Bind() events. It is okay so far but I do not get events for keystrokes. I just tried BindMenuEvent() to catch the keystroke menu events but I do not even have a MenuID to give (eg the user may not even have a menu). Thus, I found no solution yet :-(

Guessing a random menu number is very dangerous and may cause random crashes or issues later. I want to prevent that if possible :-)
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Get Event on ESC key in StringGadget

Post by #NULL »

As for the event loop. I used a simple callback which the user code has to call in its event loop.
In the module:

Code: Select all

  ; called by main program's event loop.
  ; returns #True if the event has been processed and
  ; returns #False if the event has been ignored.
  Procedure.i processEvent()
    Protected eventProcessed
    eventProcessed = #False
    ;If logToWindow And (win And IsWindow(win))
    If win And IsWindow(win)
      If EventWindow() = win
        If Event() = #PB_Event_CloseWindow
          closeLogWindow()
        EndIf
        eventProcessed = #True
      EndIf
    EndIf
    ProcedureReturn eventProcessed
  EndProcedure
In user main:

Code: Select all

        While WaitWindowEvent(10)
          eventProcessed = log::processEvent()
          If Not eventProcessed
            Select Event()
              Case #PB_Event_CloseWindow
                quit = #True
              Case #eventQuit
                quit = #True
            EndSelect
          EndIf
        Wend
So the module and main can each handle their own events. Not sure if that helps with the ESC though.
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Get Event on ESC key in StringGadget

Post by Kukulkan »

Hey #NULL,

thanks. i finally did it with a user called event handler which must be put into the main GUI loop. Not as flexible as I wanted but if he does not, the ESC key simply is not used. So it's his decision finally.
Post Reply