maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Responding to Hildon virtual keyboard keypress events (https://talk.maemo.org/showthread.php?t=74097)

marxian 2011-06-18 13:52

Responding to Hildon virtual keyboard keypress events
 
Does anyone know of a way to listen for Hildon virtual keyboard keypress events from within a Qt application? Specifically, I would like to listen for a press of the Return/Enter key when the user has finished entering text into a QLineEdit (well, my QML equivalent to be precise), so I can enable my application to respond as it does when this key is pressed on the hardware keyboard.

I'm thinking along the lines of X11/XKBlib, but I don't really know where to start with this.

laasonen 2011-06-18 14:18

Re: Responding to Hildon virtual keyboard keypress events
 
There seems to be /dev/input/uinput, but it just says "read error: No such device" when I try to read it :/

daperl 2011-06-18 14:44

Re: Responding to Hildon virtual keyboard keypress events
 
http://doc.qt.nokia.com/4.7/qwidget....eyReleaseEvent

http://doc.qt.nokia.com/4.7/qkeyevent.html

Have you tried overriding the keyReleaseEvent virtual function? The following works for me in Python:

Code:

class MainWindow(QMainWindow):
  ...
  def keyReleaseEvent(self,event)
    if event.nativeScanCode() == 36:
      print 'I hit the Return key!'
  ...

As long as the keyboard focus is right, something like the following should work too:

Code:

class MyLineEdit(QLineEdit):
  ...
  def keyReleaseEvent(self,event)
    if event.nativeScanCode() == 36:
      print 'I hit the Return key!'
  ...


daperl 2011-06-18 15:08

Re: Responding to Hildon virtual keyboard keypress events
 
Oh, duh, woops, sorry. You're talking about the virtual keyboard.

And it's to fulfill my request. Doh!

marxian 2011-06-18 15:46

Re: Responding to Hildon virtual keyboard keypress events
 
Yeah, I have no problems responding to HKB key presses. I'm not aware of any Qt applications that respond to the virtual keyboard in the way I explained, otherwise I could just take a look at the source code. I guess these kinds of problems were always likely given that Qt is basically shoehorned into Maemo5. Hopefully these things will 'just work' in Harmattan and Meego CE.

daperl 2011-06-18 20:18

Re: Responding to Hildon virtual keyboard keypress events
 
WARNING: Major Hacking Ahead

Okay, it's a two step process. Here's the first step:

Sub-class QApplication and reimplement x11EventFilter like this:

Code:

...
#include <QDebug>
#include <X11/Xlib.h>
...
bool Application::x11EventFilter(XEvent *event) {
        XClientMessageEvent *cm = (XClientMessageEvent *) event;
        if (cm->type == 33 /* ClientMessage */) {
                qDebug() << "Application::x11EventFilter" << cm->message_type << cm->format;
                for (long i=0; i<5; i++)
                        qDebug() << " " << cm->data.l[i];
        }
        return QApplication::x11EventFilter(event);
}
...

Here's the output when you click outside of the virtual keyboard:

Code:

Application::x11EventFilter 464 8
  65011750
  24
  5
  0
  0
Application::x11EventFilter 277 32
  278
  70522943
  0
  0
  0
Application::x11EventFilter 172 32
  1
  600
  0
  0
  0

Here's the output when you click the Return key:

Code:

Application::x11EventFilter 464 8
  65011750
  20
  5
  0
  0

Application::x11EventFilter 464 8
  65011750
  24
  5
  0
  0
Application::x11EventFilter 277 32
  278
  70559392
  0
  0
  0
Application::x11EventFilter 172 32
  1
  600
  0
  0
  0

If you decide to try something like the above, here's the next step in Python. I can do a proof-of-concept in C++ if need be. eventFilter() only gets invoked when the virtual keyboard pops up. focusWidget() can then be compared to the input widget of interest.

Code:

...
class EFObject(QObject):
    def eventFilter(s,o,e):
        print 'efo',o,o.focusWidget(),e,e.type()
        return False
...
class Application(QApplication):
...
app = Application(sys.argv)
oic = app.inputContext()
efo = EFObject()
oic.installEventFilter(efo)
...



All times are GMT. The time now is 21:33.

vBulletin® Version 3.8.8