[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

FXRuby: Reading keystates

Martin DeMello

1/6/2005 4:23:00 PM

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
3 Answers

Simon Strandgaard

1/6/2005 5:28:00 PM

0

On Fri, 7 Jan 2005 01:26:29 +0900, Martin DeMello
<martindemello@yahoo.com> wrote:
> 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)

--
Simon Strandgaard


Lyle Johnson

1/6/2005 7:21:00 PM

0

On Fri, 7 Jan 2005 02:28:20 +0900, Simon Strandgaard <neoneye@gmail.com> wrote:

> 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


Martin DeMello

1/7/2005 5:46:00 AM

0

Lyle Johnson <lyle.johnson@gmail.com> wrote:
> On Fri, 7 Jan 2005 02:28:20 +0900, Simon Strandgaard <neoneye@gmail.com> wrote:
>
> > 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.

Thanks to both of you!

martin