fxruby + keyboard

M

Martin Ankerl

I would like to grab all keyboard events, I especially need the left,
right, up, down keys. At the moment I have this code:

@input = FXText.new(@parent)
@input.connect(SEL_KEYPRESS) do |sender, sel, data|
# now what? data.code seems to contain a keycode
p data.code
end

There the focus has to be on the textbox, which records each keypress.
data.code seems to contain some kind of keycode, but I could not
figure out if somewhere constants are defined for the keys (like,
FX_KEY_DOWN or something like this). Any ideas how to use this
properly?

Martin
 
R

Richard Lyman

All windows should have a 'SEL_KEYPRESS' event that you could connect to.

As for the names of the constants... dunno. I always only need a few
keys (like the arrow keys), so while I'm writing it I output the
number returned from the FXEvent.code attribute, and use that
number...

-Rich
 
L

Lyle Johnson

data.code seems to contain some kind of keycode, but I could not
figure out if somewhere constants are defined for the keys (like,
FX_KEY_DOWN or something like this).

Look at fox/keys.rb, which defines symbolic constants for all of the
key codes, e.g.

require 'fox/keys'

@input.connect(SEL_KEYPRESS) do |sender, sel, data|
case data.code
when KEY_Left
puts "left"
when KEY_Right
puts "right"
when KEY_Up
puts "up"
when KEY_Down
puts "down"
end
end

You might also try searching the (old) mailing list's archives for
SEL_KEYPRESS, as it seems like this question has come up before.
Here's a link to the old mailing list's archives:

http://sourceforge.net/mailarchive/forum.php?forum_id=33510

Hope this helps,

Lyle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top