×
Namespaces

Variants
Actions
(Difference between revisions)

Listening for Symbian key events in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Merge KB into wiki)
hamishwillee (Talk | contribs)
m (Removed protection from "CS001352 - Listening for Symbian key events in Qt": Merging into Wiki)

Revision as of 09:26, 8 June 2012

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Article
Keywords: QWidget, QKeyEvent
Created: tepaa (07 Apr 2009)
Last edited: hamishwillee (08 Jun 2012)

Contents

Overview

This code snippets shows how a Qt application listens for key events.

Note: In order to use this code, you need to have Qt installed on your platform.


Preconditions


Header

This QMyWidget implemets the base class virtual keyPressEvent() method which receives key events.

//Symbian EKeyLeftArrow = 0x807
const int KeyLeftArrow = 63495;
 
//Symbian EKeyRightArrow = 0x808
const int KeyRightArrow = 63496;
 
//Symbian EKeyUpArrow = 0x809
const int KeyUpArrow = 63497;
 
//Symbian EKeyDownArrow = 0x80a
const int KeyDownArrow = 63498;
 
//Symbian EKeyDevice3
const int KeyDevice3 = 63557;
 
#include <QtGui>
 
class QMyWidget : public QWidget
{
Q_OBJECT
 
public:
QMyWidget(QWidget *parent = 0);
~QMyWidget();
 
public:
void keyPressEvent(QKeyEvent *);
};


Source

Listening for key events:

#include <QDebug>
#include "QMyWidget.h"
 
QMyWidget::QMyWidget(QWidget *parent)
: QMyWidget(parent)
{
}
 
QMyWidget::~QMyWidget()
{
}
 
void QMyWidget::keyPressEvent(QKeyEvent* event)
{
// This writes native virtual key into console output
// When pressing e.g. left arrow (native EKeyLeftArrow) output is 63495
qDebug() << event->nativeVirtualKey();
 
// Handle arrow keys and selection key events
switch (event->nativeVirtualKey())
{
case KeyLeftArrow:
{
// TODO
break;
}
case KeyRightArrow:
{
// TODO
break;
}
case KeyUpArrow:
{
// TODO
break;
}
case KeyDownArrow:
{
// TODO
break;
}
case KeyDevice3:
{
// TODO
break;
}
default:
{
break;
}
};
}

Or using values from the native Symbian e32keys.h header:

void QMyWidget::keyPressEvent(QKeyEvent* event)
{
#ifdef Q_OS_SYMBIAN
switch (event->nativeVirtualKey())
{
case EKeyUpArrow:
{
// Symbian EKeyUpArrow pressed
break;
}
};
}
#endif


Symbian TKeyEvent::iCode as QKeyEvent::nativeVirtualKey()

The following list contains Symbian C++ keycodes as Qt QKeyEvent::nativeVirtualKey() which can be received in keyPressEvent(QKeyEvent* event).

When Symbian C++ TEventCode is EEventKey, TKeyEvent::iCode equals QKeyEvent::nativeVirtualKey().

EKeyNull 0
EKeyBell 7
EKeyBackspace 8
EKeyTab 9
EKeyLineFeed 10
EKeyVerticalTab 11
EKeyFormFeed 12
EKeyEnter 13
EKeyEscape 27
EKeySpace 32
EKeyDelete 127
EKeyPrintScreen 63488
EKeyPause 63489
EKeyHome 63490
EKeyEnd 63491
EKeyPageUp 63492
EKeyPageDown 63493
EKeyInsert 63494
EKeyLeftArrow 63495
EKeyRightArrow 63496
EKeyUpArrow 63497
EKeyDownArrow 63498
EKeyLeftShift 63499
EKeyRightShift 63500
EKeyLeftAlt 63501
EKeyRightAlt 63502
EKeyLeftCtrl 63503
EKeyRightCtrl 63504
EKeyLeftFunc 63505
EKeyRightFunc 63506
EKeyCapsLock 63507
EKeyNumLock 63508
EKeyScrollLock 63509
EKeyF1 63510
EKeyF2 63511
EKeyF3 63512
EKeyF4 63513
EKeyF5 63514
EKeyF6 63515
EKeyF7 63516
EKeyF8 63517
EKeyF9 63518
EKeyF10 63519
EKeyF11 63520
EKeyF12 63521
EKeyF13 63522
EKeyF14 63523
EKeyF15 63524
EKeyF16 63525
EKeyF17 63526
EKeyF18 63527
EKeyF19 63528
EKeyF20 63529
EKeyF21 63530
EKeyF22 63531
EKeyF23 63532
EKeyF24 63533
EKeyOff 63534
EKeyIncContrast 63535
EKeyDecContrast 63536
EKeyBacklightOn 63537
EKeyBacklightOff 63538
EKeyBacklightToggle 63539
EKeySliderDown 63540
EKeySliderUp 63541
EKeyMenu 63542
EKeyDictaphonePlay 63543
EKeyDictaphoneStop 63544
EKeyDictaphoneRecord 63545
EKeyHelp 63546
EKeyDial 63547
EKeyScreenDimension0 63548
EKeyScreenDimension1 63549
EKeyScreenDimension2 63550
EKeyScreenDimension3 63551
EKeyIncVolume 63552
EKeyDecVolume 63553
EKeyDevice0 63554
EKeyDevice1 63555
EKeyDevice2 63556
EKeyDevice3 63557
EKeyDevice4 63558
EKeyDevice5 63559
EKeyDevice6 63560
EKeyDevice7 63561
EKeyDevice8 63562
EKeyDevice9 63563
EKeyDeviceA 63564
EKeyDeviceB 63565
EKeyDeviceC 63566
EKeyDeviceD 63567
EKeyDeviceE 63568
EKeyDeviceF 63569
EKeyApplication0 63570
EKeyApplication1 63571
EKeyApplication2 63572
EKeyApplication3 63573
EKeyApplication4 63574
EKeyApplication5 63575
EKeyApplication6 63576
EKeyApplication7 63577
EKeyApplication8 63578
EKeyApplication9 63579
EKeyApplicationA 63580
EKeyApplicationB 63581
EKeyApplicationC 63582
EKeyApplicationD 63583
EKeyApplicationE 63584
EKeyApplicationF 63585
EKeyYes 63586
EKeyNo 63587
EKeyIncBrightness 63588
EKeyDecBrightness 63589


Postconditions

Certain native Symbian C++ key events are handled.

88 page views in the last 30 days.
×