Advertisement
Guest User

Gtk/KeysInfo

a guest
Oct 29th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <gtkmm.h>
  2.  
  3. class MainWindow
  4. :
  5.     public Gtk::Window
  6. {
  7. public:
  8.  
  9.     MainWindow();
  10.     virtual ~MainWindow();
  11.  
  12. private:
  13.  
  14.     bool get_key_info (GdkEventKey *);
  15.  
  16.     // Gtkmm Widgets...
  17.  
  18.     Gtk::Grid grid;
  19.     Gtk::Entry entry;
  20.     Gtk::Label label;
  21. };
  22.  
  23.  
  24. MainWindow::MainWindow()
  25. {
  26.     set_title ("Window Keys");
  27.  
  28.     grid.set_column_homogeneous (false);
  29.     grid.set_row_homogeneous (false);
  30.     grid.set_row_spacing (10);
  31.  
  32.     grid.attach (entry, 0, 0, 1, 1);
  33.     grid.attach (label, 0, 1, 1, 1);
  34.  
  35.     entry.signal_key_press_event().connect (
  36.         sigc::mem_fun (*this, &MainWindow::get_key_info));
  37.  
  38.     add (grid);
  39.  
  40.     show_all_children();
  41. }
  42.  
  43. bool
  44. MainWindow::get_key_info (GdkEventKey * key)
  45. {
  46.     label.set_text (
  47.  
  48.         Glib::ustring::compose ("State   : %1\n", key->state) +
  49.         Glib::ustring::compose ("KeyVal  : %1\n", key->keyval) +
  50.         Glib::ustring::compose ("KeyCode : %1\n", key->hardware_keycode) +
  51.         Glib::ustring::compose ("Group   : %1\n", key->group) +
  52.         Glib::ustring::compose ("Modifier? %1\n", key->is_modifier));
  53.  
  54.     return true;
  55. }
  56.  
  57. MainWindow::~MainWindow()
  58. {
  59. }
  60.  
  61. int main (int argc, char *argv[])
  62. {
  63.     Glib::RefPtr<Gtk::Application> app =
  64.         Gtk::Application::create (argc, argv);
  65.  
  66.     MainWindow main_window;
  67.  
  68.     return
  69.         app->run (main_window);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement