[Win32Lib] Can't get spacebar to be responded to, sometimes
- Posted by DanM Mar 29, 2010
- 959 views
I have an app in which I wanted to make hitting the spacebar execute a routine that normally clicking on a button would do. I should be able to do that, but at that point in app, I can't get the spacebar to be responed to. At that point, I try to setFocus to the main window, (which had initially been able to pickup pressing spacebar), but that doesn't suffice to allow spacebar to be perceived.
I do use a "return" statement in a series of if-then's, to allow execution to selectivly escape further code, which seems (maybe?) to somehow be interferring with the setFocus, or maybe it's something else that I've done wrong?
Follows is a stub that, while not exactly like what I am doing/trying to do, does seem to show the problem.
-- code generated by Win32Lib IDE v1.0.4 Build July-06-2008 constant TheProgramType="exw" include Win32Lib.ew without warning -------------------------------------------------------------------------------- -- Window Window1 constant Window1 = createEx( Window, "Window1", 0, Default, Default, 400, 300, 0, 0 ) constant StatusBar3 = createEx( StatusBar, "StatusBar3", Window1, 0, 0, 0, 0, 0, 0 ) constant LText5 = createEx( LText, "FIRST, Press SPACEBAR", Window1, 116, 36, 144, 20, 0, 0 ) constant LText6 = createEx( LText, "why doesn't press ENTER set focus to window ", Window1, 44, 180, 236, 20, 0, 0 ) constant EditText7 = createEx( EditText, "EditText7", Window1, 140, 96, 48, 20, 0, 0 ) constant LText8 = createEx( LText, "THEN, Press ENTER, which SHOULD set focus to Window", Window1, 32, 68, 300, 20, 0, 0 ) constant LText9 = createEx( LText, "and allow space bar PRESS to be perceived?", Window1, 48, 204, 244, 20, 0, 0 ) constant LText10 = createEx( LText, "THEN press SPACEBAR again, should work, but doesn't", Window1, 32, 132, 304, 20, 0, 0 ) --------------------------------------------------------- -------------------------------------------------------------------------------- procedure Window1_onKeyPress (integer self, integer event, sequence params)--params is ( int keyCode, int shift,int released ) if equal(params[1], VK_SPACE) then setText(StatusBar3, "pressed SPACEBAR") setFocus(EditText7) end if end procedure setHandler( Window1, w32HKeyPress, routine_id("Window1_onKeyPress")) -------------------------------------------------------------------------------- procedure EditText7_onKeyPress (integer self, integer event, sequence params)--params is ( int keyCode, int shift,int released ) if equal(params[1], VK_ENTER)then setText(StatusBar3, "pressed ENTER") if 1 then -- would normally have other conditions here if 1 then -- and would normally have other conditions here setText(StatusBar3, "got into setFocus(Window1) section, but focus NOT on window") setFocus(Window1) return else -- do some stuff here, maybe end if -- some stuff here that I don't want to happen if execution gets -- into the "setFocus(Window1) end if end if end procedure setHandler( EditText7, w32HKeyPress, routine_id("EditText7_onKeyPress")) --------------------------------------------------------- WinMain( Window1,Normal )
Dan