The maemo platform features some hardware keys:
Key | Description | Keyboard | Key-Event |
---|---|---|---|
Move up | Arrow key up | GDK_Up | |
Move down | Arrow key down | GDK_Down | |
Move left | Arrow key left | GDK_Left | |
Move down | Arrow key right | GDK_Right | |
Select, Confirm | Return | GDK_Return | |
Open menu | F4 | GDK_F4 | |
Show home | F5 | GDK_F5 | |
Full screen | F6 | GDK_F6 | |
Increase / Zoom in / Volume up | F7 | GDK_F7 | |
Decrease / Zoom out / Volume down | F8 | GDK_F8 |
To receive an event if one of the keys is pressed you must use the key-pressed-event like the example below:
File: examplewindow.h
#ifndef GTKMM_EXAMPLEWINDOW_H #define GTKMM_EXAMPLEWINDOW_H #include <hildonmm/window.h> #include <gtkmm.h> class ExampleWindow : public Hildon::Window { public: ExampleWindow(); virtual ~ExampleWindow(); protected: //Signal handlers: virtual bool on_key_pressed(GdkEventKey* key); }; #endif //GTKMM_EXAMPLEWINDOW_H
File: examplewindow.cc
#include "examplewindow.h" #include <gtkmm.h> #include <hildonmm/banner.h> ExampleWindow::ExampleWindow() { signal_key_press_event().connect( sigc::mem_fun(*this, &ExampleWindow::on_key_pressed) ); show_all_children(); } ExampleWindow::~ExampleWindow() { } bool ExampleWindow::on_key_pressed(GdkEventKey* event) { if(!event) return false; switch (event->keyval) { case GDK_Up: Hildon::Banner::show_information(*this, "Key Up"); break; case GDK_Down: Hildon::Banner::show_information(*this, "Key Down"); break; case GDK_Left: Hildon::Banner::show_information(*this, "Key Left"); break; case GDK_Right: Hildon::Banner::show_information(*this, "Key Right"); break; case GDK_Return: Hildon::Banner::show_information(*this, "Key Select"); break; case GDK_Escape: Hildon::Banner::show_information(*this, "Key Cancel"); break; case GDK_F4: Hildon::Banner::show_information(*this, "Open menu"); break; case GDK_F5: Hildon::Banner::show_information(*this, "Show Home"); break; case GDK_F6: Hildon::Banner::show_information(*this, "Full screen"); break; case GDK_F7: Hildon::Banner::show_information(*this, "Increase"); break; case GDK_F8: Hildon::Banner::show_information(*this, "Decrease"); break; default: Hildon::Banner::show_information(*this, "Other key"); } // Returning true would stop the event now return false; }
File: main.cc
#include <hildonmm.h> #include "examplewindow.h" #include <iostream> int main(int argc, char *argv[]) { // Initialize gtkmm: Gtk::Main kit(&argc, &argv); Hildon::init(); osso_context_t* osso_context = osso_initialize("example", "0.0.1", TRUE /* deprecated parameter */, 0 /* Use default Glib main loop context */); if(!osso_context) std::cerr << "osso_initialize() failed." << std::endl; Glib::set_application_name("Hardware key example"); // Create Window and set it to Program ExampleWindow window; Hildon::Program::get_instance()->add_window(window); // Begin the main application kit.run(window); osso_deinitialize(osso_context); return 0; }