1. wxEuphoria -- keys

Gotta problem with keys:

-- problem with keys
include wxEuphoria.e
include wxMenu.e
include wxSizer.e
include wxText.e
include wxButton.e

include wildcard.e

constant PROGRAM_TITLE = "Problem With Keys",

frameWin = create(wxFrame,{0,-1,PROGRAM_TITLE,-1,-1,800,500}),
Win = create(wxPanel,{frameWin}),
boxMain = create(wxBoxSizer,{wxVERTICAL})
set_sizer(Win,boxMain)

constant
MenuBar = create(wxMenuBar,{frameWin}),
 FileMenu = create(wxMenu,{MenuBar,"&File"}),
  Menu_1 = create(wxMenuItem,{FileMenu,new_id(),"menu 1"}),
  Menu_2 = create(wxMenuItem,{FileMenu,new_id(),"menu 2"}),
  Menu_3 = create(wxMenuItem,{FileMenu,new_id(),"menu 3"}),
  Menu_4 = create(wxMenuItem,{FileMenu,new_id(),"menu 4"}),
 StuffMenu = create(wxMenu,{MenuBar,"&Stuff"}),
  Menu_10 = create(wxMenuItem,{StuffMenu,new_id(),"menu 10"}),
  Menu_20 = create(wxMenuItem,{StuffMenu,new_id(),"menu 20"}),
  Menu_30 = create(wxMenuItem,{StuffMenu,new_id(),"menu 30"}),
  Menu_40 = create(wxMenuItem,{StuffMenu,new_id(),"menu 40"}),
 HelpMenu = create(wxMenu,{MenuBar,"&Help"}),
  Menu_100 = create(wxMenuItem,{HelpMenu,new_id(),"menu 100"}),
  Menu_200 = create(wxMenuItem,{HelpMenu,new_id(),"menu 200"}),
  Menu_300 = create(wxMenuItem,{HelpMenu,new_id(),"menu 300"}),
  Menu_400 = create(wxMenuItem,{HelpMenu,new_id(),"menu 400"}),

OPTIONS = "ctrl keys: 1-button1   2-button2   T-text control   Q-quit\n",
GOAL = "Goal: ctrl keys are supposed to put the focus on a widget\n",
PROBLEM = "Problem: ctrl keys sometimes don't work  Sometimes alt- doesn't
work.\n",
NO_CHEAT = "Using the mouse is cheating.",
lblLabel = create(wxStaticText,{Win,-1,OPTIONS & GOAL & PROBLEM & NO_CHEAT}),
btnButton1 = create(wxButton,{Win,-1,"Button1"}),
btnButton2 = create(wxButton,{Win,-1,"Button2"}),
txtText = create(wxTextCtrl,{Win,-1,"",-1,-1,-1,-1,wxTE_NOHIDESEL})

add_window_to_sizer(boxMain,lblLabel,1,wxGROW,0)
add_window_to_sizer(boxMain,btnButton1,1,wxGROW,0)
add_window_to_sizer(boxMain,btnButton2,1,wxGROW,0)
add_window_to_sizer(boxMain,txtText,1,wxGROW,0)

atom void
procedure debug(sequence msg)
  void = message_box(msg,"DEBUG",0)
end procedure


integer key
 key = 0

procedure onKey(atom this,atom event_type,atom id,atom event)
  if key_event_controldown(event) then
    key = get_key_code(event)
	  key = upper(key)
    if key = '1' then
	    set_focus(btnButton1)
      debug("in Button1")
	  elsif key = '2' then
	    set_focus(btnButton2)
      debug("in Button2")
	  elsif key = 'T' then
	    set_focus(txtText)
      debug("in Text")
	  elsif key = 'Q' then
	   exit_main()
	  else
     set_focus(Win)
     debug("Try 1 2 T Q")
	  end if
	end if
end procedure
set_event_handler(Win,-1,wxEVT_KEY_UP,routine_id("onKey"))
set_event_handler(btnButton1,-1,wxEVT_KEY_UP,routine_id("onKey"))
set_event_handler(btnButton2,-1,wxEVT_KEY_UP,routine_id("onKey"))
set_event_handler(txtText,-1,wxEVT_KEY_UP,routine_id("onKey"))

set_focus(Win)
wxMain(frameWin)


new topic     » topic index » view message » categorize

2. Re: wxEuphoria -- keys

Jerry Story wrote:
> 
> Gotta problem with keys:
> 

<snipped>

It only seems to work when I have the mouse over the window.  I tested
this using coLinux and a Cygwin X-server, so I suspect that it has the 
focus follows mouse setting on.  If you're not going to process the 
key-up event, you need to add a skip(event) in there.
procedure onKey(atom this,atom event_type,atom id,atom event)

  if key_event_controldown(event) then
    key = get_key_code(event)
	  key = upper(key)
    if key = '1' then
	    set_focus(btnButton1)
      debug("in Button1")
	  elsif key = '2' then
	    set_focus(btnButton2)
      debug("in Button2")
	  elsif key = 'T' then
	    set_focus(txtText)
      debug("in Text")
	  elsif key = 'Q' then
	   exit_main()
	  else
     set_focus(Win)
     debug("Try 1 2 T Q")
	  end if
	 else
	   skip(event)
	end if
end procedure


Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu