如何使用 Tk 在 Ruby 中最轻松地确定键盘上不寻常键的键符?

How can I determine most easily the keysyms of unusual keys on my keyboard, in Ruby, with Tk?

我正在使用 Ruby 和 Tk。我想知道我不寻常的键盘上各种奇数键的键符。我想知道它们到底是什么,而不仅仅是一些参考(例如 this) 说他们应该。

此代码对我在 Windows 7:

上使用 Ruby 2.2.5(使用 Tk 8.5.12)有效
# coding: utf-8

require 'tk'

def lambda_keypress
  @lambda_keypress ||= Kernel.lambda do |key_code, key_symbol|
    puts "lambda_keypress invoked with keycode #{key_code} and keysym #{key_symbol}."
  end
end

def root
  $root ||= begin
    Tk::Encoding.encoding = ''.encoding
    TkRoot.new
  end
end

root.bind :KeyPress, lambda_keypress, '%k %K'
Tk.mainloop