FXRuby: Reading keystates

M

Martin DeMello

How do I read the pressed state of the shift, ctrl etc keys from within
FXRuby? (And is the correct way to read a Ctrl-A to trap an OnKeypress
for A and check if Ctrl is pressed?)

martin
 
S

Simon Strandgaard

How do I read the pressed state of the shift, ctrl etc keys from within
FXRuby? (And is the correct way to read a Ctrl-A to trap an OnKeypress
for A and check if Ctrl is pressed?)


def onKeypress(sender, sel, event)
p "keysym=#{event.code} state=#{event.state} text=#{event.text}"
if (event.state & CONTROLMASK) != 0
if event.text == 'a'
p "we got a"
end
end
end



elsewhere you must do

widget.connect(SEL_KEYPRESS, method:)onKeypress))


(untested)
 
L

Lyle Johnson

def onKeypress(sender, sel, event)
p "keysym=#{event.code} state=#{event.state} text=#{event.text}"
if (event.state & CONTROLMASK) != 0
if event.text == 'a'
p "we got a"
end
end
end

I would change one thing, and that is to check the event.code field
instead of the event.text field, i.e.

if (event.state & CONTROLMASK) != 0
if event.code == KEY_a
...
end
end

... also untested ;)

-- Lyle
 
M

Martin DeMello

Lyle Johnson said:
I would change one thing, and that is to check the event.code field
instead of the event.text field, i.e.

Thanks to both of you!

martin
 

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,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top