[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

keystrokes detection for non-control, meta key

teeshift

1/15/2007 9:41:00 AM

I have tried

@canvas.bind('k', proc{|e| })
@canvas.bind('KeyPress-k', proc{|e| })
@canvas.bind('Key-k', proc{|e| })

well... none of them work.
Any wise words?

Thank you.

Tee Shift

5 Answers

Joel VanderWerf

1/15/2007 8:15:00 PM

0

teeshift wrote:
> I have tried
>
> @canvas.bind('k', proc{|e| })
> @canvas.bind('KeyPress-k', proc{|e| })
> @canvas.bind('Key-k', proc{|e| })
>
> well... none of them work.

Try
root.bind("Key-k") {...}

IIRC, the reason is that key events are sent to the top level window
unless you have focused on a subwindow.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

teeshift

1/17/2007 1:30:00 AM

0


Thank you Joel.

I tried and it worked. Now, is there a way to find which key users have
pressed without
specifying it first?

@canvas.bind('Key', proc{})

what should be inside the 'proc'? I know e.x, e.y but have tried
e.keys, e.key, e.value
without success and did not find any valuable information on Event.

Thank you.

Tee


Joel VanderWerf wrote:
> teeshift wrote:
> > I have tried
> >
> > @canvas.bind('k', proc{|e| })
> > @canvas.bind('KeyPress-k', proc{|e| })
> > @canvas.bind('Key-k', proc{|e| })
> >
> > well... none of them work.
>
> Try
> root.bind("Key-k") {...}
>
> IIRC, the reason is that key events are sent to the top level window
> unless you have focused on a subwindow.
>
> --
> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Joel VanderWerf

1/17/2007 7:23:00 AM

0

teeshift wrote:
> Thank you Joel.

You're welcome!

> I tried and it worked. Now, is there a way to find which key users have
> pressed without
> specifying it first?
>
> @canvas.bind('Key', proc{})

I was curious about this too.

To find out, add something like this:

root.bind "Key" do |stuff|
p stuff, stuff.methods
end

Then press a key in your window. It turns out that the "stuff" is an
Event instance, and it has @keysym="h", and there are #keycode and
#keysym methods.

If you add the line

p stuff.keycode, stuff.keysym

then you can see that pressing the "h" key gives this output:

43
"h"

So probably the #keysym method is what you want.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

teeshift

2/6/2007 12:48:00 PM

0


Thanks. Joel.

Sorry for the late reply. Did not have much time doing doodling on
Ruby.

The other question, I will post it on the group with a different
title.
Is there any method to get a pixel from the canvas? I can draw a pixel
(painfully by using either
line or rectangle, same storage anyway) but can I sample a pixel ?

I vaguely recall that Java seems to do that. Do not know if Qt 4 does
it. ( A complete novice on Qt4
and haven't coded Java for years.)

teeshift

2/6/2007 1:01:00 PM

0


Ignore my previous message. The answer is at

http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/f0cd7b379e8b195f/e9fded6c453a28bb?lnk=gst&q=get+pixel+canvas&rnum=1#e9fded...

However, I would love to know about the Qt4 and Java. Does it work on
their canvas?