Reply
Thread Tools
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#1
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.
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 
laasonen's Avatar
Posts: 565 | Thanked: 618 times | Joined on Jun 2010 @ Finland
#2
There seems to be /dev/input/uinput, but it just says "read error: No such device" when I try to read it :/
__________________
Couple of my applications:
ConnLock - Advanced phone lock
Sanakirja.org - A Sanakirja.org dictionary client
Wlan Driver Selector Applet - Switch easily between stock and bleeding edge drivers
 

The Following User Says Thank You to laasonen For This Useful Post:
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#3
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!'
  ...
__________________
N9: Go white or go home

Last edited by daperl; 2011-06-18 at 14:57.
 

The Following User Says Thank You to daperl For This Useful Post:
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#4
Oh, duh, woops, sorry. You're talking about the virtual keyboard.

And it's to fulfill my request. Doh!
__________________
N9: Go white or go home
 
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#5
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.
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#6
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)
...
__________________
N9: Go white or go home
 

The Following 3 Users Say Thank You to daperl For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 16:30.