Hardware keys

The maemo platform features some hardware keys:

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

Example

To receive an event if one of the keys is pressed you have to use the key-pressed-event like the example below:

examplewindow.h
//$Id: examplewindow.h,v 1.1 2003/11/03 09:29:56 murrayc Exp $ -*- c++ -*-

/* gtkmm example Copyright (C) 2002 gtkmm development team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <hildon-libsmm/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

examplewindow.cc
//$Id: examplewindow.cc,v 1.5 2004/03/25 14:35:34 murrayc Exp $ -*- c++ -*-

/* gtkmm example Copyright (C) 2002 gtkmm development team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include "examplewindow.h"
#include <gtkmm.h>
#include <hildon-libsmm/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)
{
	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");
	}

	// Return true would stop the event now
	return false;
}

main.cc
//$Id: main.cc,v 1.1 2003/11/03 09:29:56 murrayc Exp $ -*- c++ -*-

/* gtkmm example Copyright (C) 2002 gtkmm development team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <hildon-libsmm/program.h>
#include <gtkmm/main.h>

#include "examplewindow.h"

/* This is the C++ version of the example in the tutorial */

int main(int argc, char *argv[])
{
    /* Initialize the GTKmm. */
    Gtk::Main kit(&argc, &argv);

    /* Create the hildon program and setup the title */
   	Hildon::Program program;
    
    Glib::set_application_name("Hardware key example");

    /* Create Window and set it to Program */
    ExampleWindow window;
	program.add_window(window);

    /* Begin the main application */
    window.show_all();
    kit.run(window);
	
    /* Exit */
    return 0;

}