[erlang-questions] Capturing keystrokes in wxWindows Issues + Segmentation Fault

Tom Parker thpr@REDACTED
Fri May 4 03:09:37 CEST 2012

Background: I'm new to Erlang, so just getting the hang of things...I'm trying to get key events back from a window, and exploring how to do that.  

If I do this in the erl shell:

F=wxFrame:new(Wx,-1,"Hello, World!").
Canvas = wxPanel:new(F, []).
wxEvtHandler:connect(F,key_down, [{callback, fun(Rec, Obj) -> io:format("Received:~p~n",[Rec]) end}]).

Issue #1: With this setup, I get no events back (regardless of what I select in the UI prior to pressing any keys).

If I change to key_up, I will get events, but ...

Issue #2: ... the events only show up after I click into the (white due to the wxDC:clear call) Canvas, not just the title bar of the window or the other (gray) part of the Frame (see below for where the focus is before clicking in the Canvas).  I'm unsure why it has to be a child that has focus for me to get a callback.

I also get char_hook events if I use that instead of key_down

Issue #3: ... but no char_hook for things like the "Shift" key - the ONLY event I seem to be able to get from Shift is "key_up"

Issue #4: No char events at all if I connect to those (just like key_down)

(I think those are the 4 types of keyboard events I might find)

Since I wanted to try to capture events even when the title bar was clicked (vs just contents of the window), I set up a test to identify where the focus is when I select the title bar.  Code not relevant here, but clicking on the title bar of the window puts focus (as reported by wxWindow.findFocus() into a wxWindow that is not Frame F. 
Transferring Focus to the Frame doesn't help receipt of events:
Clicking into the Canvas puts focus on Canvas, and allows me to receive key_up and (some) char_hook events:

Attempting the connect the event handler to Wx produces errors, so that doesn't work (fair enough), but it turns out Wx really isn't the parent of F.  The wxWindow (ID 0) that has the focus IS the parent of Frame F as reported by wxWindow.getParent(F).... so I tried this:


F=wxFrame:new(Wx,-1,"Hello, World!").
wxEvtHandler:connect(Fparent,key_down, [{callback, fun(Rec, Obj) -> io:format("Received:~p~n",[Rec]) end}]).

Issue #5: This causes a segmentation fault.

Erlang 15B01 from a source build (plain untar, make, make install... necessary since I wanted wxWindows) on Ubuntu 10.04-LTS

Any thoughts, ideas or feedback?  Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120503/d8530813/attachment.htm>

More information about the erlang-questions mailing list