keystrokes detection for non-control, meta key

T

teeshift

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
 
J

Joel VanderWerf

teeshift said:
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.
 
T

teeshift

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
 
J

Joel VanderWerf

teeshift said:
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.
 
T

teeshift

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

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

Forum statistics

Threads
474,232
Messages
2,571,168
Members
47,803
Latest member
ShaunaSode

Latest Threads

Top