@@ -23,8 +23,8 @@ import QtQuick 2.0
2323
2424 A filter to handle events triggered by pressing physical keys on a device.
2525 Keys included are
26− * Volume Increase
2726 * Volume Decrease
27+ * Volume Increase
2828 * Power
2929
3030 This allows for handling the following events
@@ -36,10 +36,14 @@ import QtQuick 2.0
3636QtObject {
3737 id: root
3838
39+ signal powerPressed()
40+ signal screenshotPressed()
3941 signal volumeDownPressed()
4042 signal volumeUpPressed()
41− signal screenshotPressed()
4243
44+ property bool eventAccepted: false
45+
46+ property bool aPowerKeyWasReleased: true
4347 property bool powerKeyPressed: false
4448
4549 property bool aVolumeKeyWasReleased: true
@@ -47,16 +51,25 @@ QtObject {
4751 property bool volumeUpKeyPressed: false
4852
4953 function onKeyPressed(key) {
54+ /* Determine what key was pressed */
55+
56+ // Power Key
5057 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
58+ eventAccepted = true;
5159 powerKeyPressed = true;
5260 }
61+
62+ //Volume Keys
5363 else if (key == Qt.Key_VolumeDown) {
64+ eventAccepted = true;
5465 volumeDownKeyPressed = true;
5566 }
5667 else if (key == Qt.Key_VolumeUp) {
68+ eventAccepted = true;
5769 volumeUpKeyPressed = true;
5870 }
5971
72+ /* Determine how to handle it */
6073 if (volumeDownKeyPressed && volumeUpKeyPressed) {
6174 if (aVolumeKeyWasReleased) {
6275 bothVolumeKeysPressed();
@@ -64,28 +77,38 @@ QtObject {
6477 aVolumeKeyWasReleased = false;
6578 }
6679 else if (volumeDownKeyPressed) {
67− if (powerKeyPressed) {
80+ if (powerKeyPressed && aPowerKeyWasReleased) {
6881 screenshotPressed();
69− } else {
82+ aPowerKeyWasReleased = false;
83+ // Don't emit volumeDownPressed if power key is held
84+ } else if (aPowerKeyWasReleased){
7085 volumeDownPressed();
7186 }
7287 }
7388 else if (volumeUpKeyPressed) {
7489 volumeUpPressed();
7590 }
91+
92+ return eventAccepted;
7693 }
7794
7895 function onKeyReleased(key) {
7996 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
97+ eventAccepted = true;
8098 powerKeyPressed = false;
99+ aPowerKeyWasReleased = true;
81100 }
82101 else if (key == Qt.Key_VolumeDown) {
102+ eventAccepted = true;
83103 volumeDownKeyPressed = false;
84104 aVolumeKeyWasReleased = false;
85105 }
86106 else if (key == Qt.Key_VolumeUp) {
107+ eventAccepted = true;
87108 volumeUpKeyPressed = false;
88109 aVolumeKeyWasReleased = true;
89110 }
111+
112+ return eventAccepted;
90113 }
91114}