Listening for Symbian key events in Qt
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
|||
| (15 intermediate revisions by 7 users not shown) | |||
| Line 1: | Line 1: | ||
| − | {{ | + | [[Category:Qt]][[Category:Symbian]][[Category:Symbian C++]][[Category:UI]] |
| − | | | + | {{ArticleMetaData <!-- v1.2 --> |
| − | | | + | |sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> |
| − | |devices=5800 XpressMusic | + | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> |
| − | | | + | |devices= Nokia 5800 XpressMusic |
| − | | | + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> |
| − | | | + | |platform= S60 3rd Edition, FP1, FP2<br>S60 5th Edition |
| − | |keywords=QWidget, QKeyEvent | + | |devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) --> |
| + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | ||
| + | |signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= QWidget, QKeyEvent | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 20090407 | ||
| + | |author= [[User:Tepaa]] | ||
| + | <!-- The following are not in current metadata --> | ||
| + | |subcategory= UI | ||
| + | |id= CS001352 | ||
}} | }} | ||
==Overview== | ==Overview== | ||
| − | This code snippets shows how Qt | + | This code snippets shows how a Qt application listens for key events. |
| − | '''Note''': In order to use this code, you need to have Qt | + | '''Note''': In order to use this code, you need to have Qt installed on your platform. |
==Preconditions== | ==Preconditions== | ||
| − | * Install | + | * Install [[Qt SDK]] |
| − | + | ||
==Header== | ==Header== | ||
| − | + | This {{Icode|QMyWidget}} implemets the base class virtual {{Icode|keyPressEvent()}} method which receives key events. | |
| − | <code cpp> | + | <code cpp-qt> |
//Symbian EKeyLeftArrow = 0x807 | //Symbian EKeyLeftArrow = 0x807 | ||
const int KeyLeftArrow = 63495; | const int KeyLeftArrow = 63495; | ||
| Line 58: | Line 74: | ||
==Source== | ==Source== | ||
| − | Listening key events | + | Listening for key events: |
| − | <code cpp> | + | <code cpp-qt> |
#include <QDebug> | #include <QDebug> | ||
#include "QMyWidget.h" | #include "QMyWidget.h" | ||
| Line 115: | Line 131: | ||
</code> | </code> | ||
| − | Or using values from native Symbian e32keys.h header | + | Or using values from the native Symbian {{Icode|e32keys.h}} header: |
| − | <code cpp> | + | <code cpp-qt> |
void QMyWidget::keyPressEvent(QKeyEvent* event) | void QMyWidget::keyPressEvent(QKeyEvent* event) | ||
{ | { | ||
| Line 135: | Line 151: | ||
==Symbian TKeyEvent::iCode as QKeyEvent::nativeVirtualKey()== | ==Symbian TKeyEvent::iCode as QKeyEvent::nativeVirtualKey()== | ||
| − | |||
| − | |||
| − | When Symbian TEventCode is EEventKey, | + | The following list contains Symbian C++ keycodes as Qt {{Icode|QKeyEvent::nativeVirtualKey()}} which can be received in {{Icode|keyPressEvent(QKeyEvent* event)}}. |
| + | |||
| + | When Symbian C++ {{Icode|TEventCode}} is {{Icode|EEventKey}}, {{Icode|TKeyEvent::iCode}} equals {{Icode|QKeyEvent::nativeVirtualKey()}}. | ||
<code> | <code> | ||
| Line 258: | Line 274: | ||
==Postconditions== | ==Postconditions== | ||
| − | + | Certain native Symbian C++ key events are handled. | |
| − | [[Category: | + | [[Category:Code Snippet]][[Category:Code Snippet]] |
Latest revision as of 04:17, 11 October 2012
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
S60 5th Edition
Article
Keywords: QWidget, QKeyEvent
Created: tepaa
(07 Apr 2009)
Last edited: hamishwillee
(11 Oct 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
- Install Qt SDK
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.

