Keystrokes detection for non-control, meta key

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

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.

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

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#e9fded6c453a28bb

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

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.

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.)