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_press_event like the example below:
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H
#include <hildonmm/window.h>
#include <gtkmm.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
// Signal handlers:
bool on_key_pressed(GdkEventKey* key);
};
#endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: main.cc
#include <hildonmm.h>
#include "examplewindow.h"
int main(int argc, char *argv[])
{
// Initialize gtkmm:
Gtk::Main kit(&argc, &argv);
Hildon::init();
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);
return 0;
}
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();
}
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;
}