Re: Win32Lib Losing Keys
- Posted by Guillermo Bonvehi <knixeur at speedy.com.ar> Jul 08, 2004
- 496 views
On Wed, 07 Jul 2004 18:49:40 -0700 cklester <guest at RapidEuphoria.com> wrote: > > > posted by: cklester <cklester at yahoo.com> > > Derek Parnell wrote: > > > > cklester wrote: > > > > > > Can somebody please help me with this problem? Run the code below. > > > Type anything. You'll see the result in the statusbar. Now click the > > > button. Try typing again. No KeyPress response. > > > > > It all depends on what you are trying to achieve. Is it really important > > that > > you react to the Window, rather than *any* other control, getting a key > > event? > > Well, press the space bar after clicking the button. It's important > that the spacebar not push the button. > > > My guess is that you wish to do something when a certain key is pressed, > > regardless of which control currently has focus. If that is so, > > trying using > > > > setHandler(Screen, w32HKeyDown, ...) > > > > this will trap all key presses, regardless of which control currently > > has focus. If you need to know which control has focus, call the > > getSelf() function inside the Screen-event handler. > > How do I prevent the spacebar from clicking the button? > > The following code sets the event handler to the Screen... but after > clicking the button, pressing the spacebar still clicks it. That's > bad behavior. > > -- code generated by Win32Lib IDE v0.18.14 > > include Win32Lib.ew > without warning > > > -------------------------------------------------------------------------------- > -- Window Window1 > constant Window1 = createEx( Window, "Window1", 0, Default, Default, 434, 352, > 0, 0) > constant StatusBar2 = createEx( StatusBar, "StatusBar2", Window1, 0, 0, 0, 0, > 0, 0) > constant PushButton4 = createEx( PushButton, "PushButton4", Window1, 96, 124, > 88, 28,0, 0 ) > --------------------------------------------------------- > > -------------------------------------------------------------------------------- > procedure Window1_onKeyPress (integer self, integer event, sequence > params)--params is ( int keyCode, int shift ) > setText(StatusBar2, "Got key " & params[1] & "." ) > end procedure > setHandler( Screen, w32HKeyPress, routine_id("Window1_onKeyPress")) > > WinMain( Window1,Normal ) To avoid the space bar hit you must returnValue(-1) in that procedure if my memory doesn't fail...