It is currently Mon Jul 23, 2018 2:25 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [done] Get Event on ESC key in StringGadget
PostPosted: Wed Jul 11, 2018 2:21 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jun 06, 2005 2:35 pm
Posts: 1153
Location: germany
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.

Top
 Profile  
Reply with quote  
 Post subject: Re: Get Event on ESC key in StringGadget
PostPosted: Wed Jul 11, 2018 3:21 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 733
Location: right here
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Event on ESC key in StringGadget
PostPosted: Wed Jul 11, 2018 4:18 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jun 06, 2005 2:35 pm
Posts: 1153
Location: germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Event on ESC key in StringGadget
PostPosted: Thu Jul 12, 2018 12:29 am 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1556
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 :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Event on ESC key in StringGadget
PostPosted: Thu Jul 12, 2018 8:11 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jun 06, 2005 2:35 pm
Posts: 1153
Location: germany
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 :-)


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Event on ESC key in StringGadget
PostPosted: Thu Jul 12, 2018 11:24 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 733
Location: right here
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:
  ; 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:
        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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get Event on ESC key in StringGadget
PostPosted: Thu Jul 12, 2018 12:00 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jun 06, 2005 2:35 pm
Posts: 1153
Location: germany
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye