GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Aug-2006, 00:20
harroldm harroldm is offline
New Member
 
Join Date: Jul 2006
Location: Tasmania, Australia
Posts: 2
harroldm is on a distinguished road

Handling keyup events.


Hi,

First post, be gentle.

Im trying to make a Window in FLTK2.0 (DevPack version, Windows) that can receive both key(down) and keyup events.

My objective is to have a runtime table of 'hotkeys' the user can press to trigger the PUSH/RELEASE of a Button.

My first attempt used shortcuts in my Window, but it doesn't 'animate' the PUSH/RELEASE of the corresponding Button, and only fires a callback on PUSH anyway.

My second attempt subclassed Window, and tried to get the keystrokes in handle().
This failed, seems only Widget in focus() gets KEYUP events. I could however, get ALL the KEY events.

My third attempt subclassed Button, uses the hotkey map (key_2_cmd) to see if it has a defined hotkey, and if so, sends the appropriate PUSH or RELEASE event to the Window (via handle_ex - a custom function).

This works perfectly for SOME keys, but not others. I can use fltk::PageDownKey for example , but not fltk::PageUpKey. The keys available to me are consistent across multiple versions of Windows ...but only about half the keyboard. With the 'broken' keys, I get neither KEY or KEYUP events.

It appears that my Button is not receiving all the keys, only some. It also smells like a dirty hack based on guess work.

Does anybody know what I'm doing wrong, or if this is an 'undocumented feature' in FLTK2.

I've included the (not quite right) code, sorry for the length, it uses lots of buttons.

cheers,

Matt from Tasmania (scratching head).
Attached Files
File Type: zip source.zip (3.1 KB, 32 views)
  #2  
Old 24-Aug-2006, 07:43
MatthiasWM MatthiasWM is offline
VIP
 
Join Date: Nov 2004
Posts: 62
MatthiasWM will become famous soon enough

Re: Handling keyup events.


Quote:
Originally Posted by harroldm
It appears that my Button is not receiving all the keys, only some. It also smells like a dirty hack based on guess work.

FL_KEYBOARD events are usually only sent to the widget that has focus. If that widget does not use the event, they are resnt up the hierarchy, until a widget does. If no widget eats the event, they are resent as FL_SHORTCUT. Finally, if nobody used them, they are sent to whatever you defined with Fl::add_handler.

FL_KEYUP events are normally only sent to the focus widget and only if it used the corresponding keydown (at least that is the intention ;-). )

So you have two ways out: as soon as you get your key event, also set the focus to that widget. You should then get a keyup as well. Or watch events with add_handler and then set button colors accordingly. None of that helps though, if another widget with higher priority already uses your shortcut for something else.
  #3  
Old 24-Aug-2006, 08:41
harroldm harroldm is offline
New Member
 
Join Date: Jul 2006
Location: Tasmania, Australia
Posts: 2
harroldm is on a distinguished road

Re: Handling keyup events.


Thanks for that.

I got it working by subclassing all my widgets and sending all KEY and KEYUP events back to the parent(). Some keys were still missing until I subclassed everything. I suppose this is because I was blindly ignoring the focus() issue.

I was still uncomfortable with my solution and hoped the forum might shed some light on a better way.

If I keep track of which Widget has focus() I can trap the pesky KEYUP event (add_handler - as you said) and greatly expand the Widgets can use.

I realise now that this was already documented, so I feel a little blonde.

Cheers!
  #4  
Old 24-Aug-2006, 08:48
MatthiasWM MatthiasWM is offline
VIP
 
Join Date: Nov 2004
Posts: 62
MatthiasWM will become famous soon enough

Re: Handling keyup events.


Quote:
Originally Posted by harroldm
I realise now that this was already documented, so I feel a little blonde.

No worries. UI programming is not easy, particularly if you try to get some extra effects going... .
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dialog bar (CDialog Bar) activex(flexgrid control) fire events SteelX MS Visual C++ / MFC Forum 1 20-Mar-2008 03:33
Opinion on my code and a c++ class question FlipNode C++ Forum 7 07-Feb-2006 08:15
Microsoft Word Event handling help... Arthur M MS Visual C++ / MFC Forum 0 03-Jan-2005 20:09
MFC Application - How to catch Keyboard and Mouse events wodek MS Visual C++ / MFC Forum 1 13-Dec-2004 02:35
Win32 API Keyboard events JBowe MS Visual C++ / MFC Forum 4 04-Mar-2004 11:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:44.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.