Results 1 to 2 of 2

Thread: On Screen Keyboard Problem

  1. #1
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default On Screen Keyboard Problem

    hi all!

    i'm currently developing an on screen keyboard to be use for my touch screen application. i'm using qt 3.3 in unix/x11.

    i have already a keyboard layout, and codes with in the keyboard keys. i used XSendEvent() function to send an event.

    all the letters from a-z and special characters works fine, except for the function keys f1-f12, tab, enter and arrow keys.

    heres my code in creating event:
    Qt Code:
    1. XKeyEvent createKeyEvent(Display *display, Window &win,
    2. Window &winRoot, bool press,
    3. int keycode, int modifiers)
    4. {
    5. XKeyEvent event;
    6.  
    7. event.display = display;
    8. event.window = win;
    9. event.root = winRoot;
    10. event.subwindow = None;
    11. event.time = CurrentTime;
    12. event.x = 1;
    13. event.y = 1;
    14. event.x_root = 1;
    15. event.y_root = 1;
    16. event.same_screen = TRUE;
    17. event.state = modifiers;
    18. event.keycode = XKeysymToKeycode(display,keycode);
    19. if(press)
    20. event.type = KeyPress;
    21. else
    22. event.type = KeyRelease;
    23.  
    24. return event;
    25. }
    To copy to clipboard, switch view to plain text mode 

    for the sendkey event:

    Qt Code:
    1. int tsKeyboardWidget::SendKeys(int keycode)
    2. {
    3. //modifier=pubModifier->text().toInt();
    4. // Obtain the X11 display.
    5. Display *display = XOpenDisplay(NULL);
    6. if(display == NULL)
    7. return -1;
    8.  
    9. // Get the root window for the current display.
    10. Window winRoot;// = XRootWindow(display,1);
    11.  
    12. // Find the window which has the current keyboard focus.
    13. Window winFocus;
    14. int revert=RevertToParent;
    15. //int RevertToParent=0;
    16. XGetInputFocus(display, &winFocus,&revert);
    17. winFocus=winFocus+1;
    18.  
    19.  
    20. // Send a fake key press event to the window.
    21. XSelectInput(display, winFocus,FocusChangeMask|KeyPressMask|KeyReleaseMask);
    22. XMapWindow(display, winFocus);
    23.  
    24. XKeyEvent event = createKeyEvent(display, winFocus, winRoot, true, keycode, modifier);
    25.  
    26. XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
    27.  
    28. event = createKeyEvent(display, winFocus, winRoot, false, keycode, modifier);
    29. XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
    30. XCloseDisplay(display);
    31. return 0;
    32. }
    To copy to clipboard, switch view to plain text mode 

    for button press, for example when i press the button A.

    Qt Code:
    1. void tsKeyboardWidget::btnA_clicked()
    2. {
    3. SendKeys(Qt::Key_A);
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 

    when i send Qt::Key_A it works.

    my problem is, when i send the Qt::Key_Tab or Qt::Key_Enter, nothing happens.

    is there something wrong with code? or is there another way to send the TAB or ENTER key as what the real keyboard does?

    thnks...
    Last edited by cutie.monkey; 16th July 2008 at 06:28. Reason: updated contents

  2. #2
    Join Date
    Apr 2006
    Location
    Denmark / Norway
    Posts
    67
    Thanks
    3
    Thanked 12 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: On Screen Keyboard Problem

    Hi

    Qt::Key_Tab isn't the same as keycode required in createKeyEvent.

    The keycodes on X11 can be found here:
    http://cvsweb.xfree86.org/cvsweb/xc/....h?rev=1.1.1.4

    You need to either make a mapping between QT::Key_XX and XK_XX, or use XK_XX directly.

    cheers,
    leif

Similar Threads

  1. QProcess-startDetached and Console screen problem
    By ramazangirgin in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2008, 08:05
  2. Available Screen Problem
    By December in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2007, 16:01
  3. Keyboard shortcuts problem.
    By Lemming in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2006, 16:12
  4. hide/show screen update problem
    By SkripT in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2006, 17:49
  5. Problem with screen update...
    By mysearch05 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2006, 18:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.