Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login

tips_key_pressed

Investigate what key is pressed

Run this script and press key what you investigate. You can get key value and that Gdk::Keyval constant easily.

require 'gtk2'

window = Gtk::Window.new
window.add_events(Gdk::Event::KEY_PRESS)
window.add(Gtk::Label.new("Press Key!"))

window.signal_connect("key-press-event") do |w, e|
  p "#{e.keyval}, Gdk::Keyval::GDK_#{Gdk::Keyval.to_name(e.keyval)}"
end

window.set_default_size(100, 100).show_all

Gtk.main

Also note that you can use Gdk::Keyval.to_name() to find out the given name, if you have an event.

Example:

puts Gdk::Keyval.to_name(event.keyval)

P.S.

Please notice that the above script script can get the key value on your own environment only. Some key values have different values on each environments.

Last modified:2015/08/03 19:53:47
Keyword(s):
References:[tips]