Re: Win32Lib Losing Keys

new topic     » goto parent     » topic index » view thread      » older message » newer message

cklester wrote:
> 
> 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 )


You can put this patch into win32lib...

If the routine called 'fDoKeys', move down till you find
these lines...

            elsif iMsg = WM_KEYDOWN then
                if length(lUserReturn) >= 2 then
                    if equal(lUserReturn[1], w32KH_SetFocus) then
                        lNewFocus = lUserReturn[2]
                    end if
                end if

Then insert these lines between the two 'end if' lines in the
above code...

                elsif lUserReturn[1] = -1 then
                    -- Ignore this keystroke
                    lRC = {kMainMsg}

Finally, do this in your application code...

procedure PushButton4_onKeyDown (integer self, integer event, sequence
params)--params is ( int keyCode, int shift )
    if params[1] = ' ' then
        returnValue(-1)
    end if
end procedure
setHandler( PushButton4, {w32HKeyDown}, routine_id("PushButton4_onKeyDown"))

-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu