Re: How to capture key-press-event on gtk:event-box?
Espen S Johnsen <[email protected]> 28 Sep 2006 14:39:02 +0200
| Newsgroups | gmane.lisp.clg.devel |
|---|---|
| Message-ID | <[email protected]> |
Kevin L <[email protected]> writes: > I've got an app that creates multiple windows, each window having an > event-box containing a drawing-area. I am having trouble capturing key > press/release events from the event-box. Here is the relevant code that > sets up a window: > > [code deleted] > > Everything works except that when I have a window focused and hit a key, > nothing happens. > > I have tried tying the keyboard events to the drawing-area, but same > problem. That is because the toplevel windows which has the focus is receiving the keyboard events. If you don't have other widgets inside the toplevel which needs to receive keyboard events, you could probably just connect your keyboard handler to the toplevel. > I captured enter-notify-event and leave-notify-event specifically so I > had a place in code to set keyboard focus on the event-box, but I'm not > finding any functions to do that. I can't set focus on the window or on > the event-box. > > I feel like maybe two lines of code in #'system-enter will fix this, but > I've no idea what they are. The two lines of code you need are something like this: (setf (gtk:widget-can-focus-p event-box) t) (gtk:widget-grab-focus event-box) You should only need to call widget-grab-focus when you are giving focus from one widget inside the toplevel to another, and not in every enter-notify events. -- Espen ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV