1. win32lib key handling

I sent this to grape_vine, but what the heck... here's part of a 'quiz'
engine...

I don't know if this will help, but the following code fragment:
...lets me select one of three radio buttons, and perform one of two actions
using normal buttons.
....lets me scroll thru the 5 items using the arrow keys.
....items are selected with the enter key.
....Choice1,Choice2,Choice3, are radios, which is why I'm doing all this
setCheck() stuff,  to select only one of three  blink
-------------------

procedure do_Choice1(integer key,integer s)
 if key=13 then setCheck(Choice1,1) -- select ONLY one of three 'radios'
  setCheck(Choice2,0)  setCheck(Choice3,0)
 elsif key=#28 then setFocus(Choice2) -- or go down one
 elsif key=#26 then setFocus(Button11) end if -- ( wrap to bottom button ! )
end procedure
onKeyDown[Choice1] = routine_id("do_Choice1")

procedure do_Choice2(integer key,integer s)
 if key=13 then setCheck(Choice2,1)
  setCheck(Choice1,0)  setCheck(Choice3,0)
 elsif key=#28 then setFocus(Choice3)  -- go down to next
 elsif key=#26 then setFocus(Choice1) end if  -- or go up
end procedure
onKeyDown[Choice2] = routine_id("do_Choice2")

procedure do_Choice3(integer key,integer s)
 if key=13 then setCheck(Choice3,1)
  setCheck(Choice1,0)  setCheck(Choice2,0)
 elsif key=#28 then setFocus(Button10)
 elsif key=#26 then setFocus(Choice2) end if
end procedure
onKeyDown[Choice3] = routine_id("do_Choice3")

procedure do_Btn10(integer key,integer s)
 if key=13 then ask()   -- do this action
 elsif key=#28 then setFocus(Button11)
 elsif key=#26 then setFocus(Choice3) end if
end procedure
onKeyDown[Button10] = routine_id("do_Btn10")

procedure do_Btn11(integer key,integer s)
 if key=13 then close_quiz()   -- or do this action
 elsif key=#28 then setFocus(Choice1)
 elsif key=#26 then setFocus(Button10) end if
end procedure
onKeyDown[Button11] = routine_id("do_Btn11")

....pretty wordy, but it works, Wolf

http://www.king.igs.net/~wolfritz
http://www.king.igs.net/~wolfritz/tutor.htm

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu