Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get keyboard input PS/2 scan codes or USB usage codes in Linux?
Forum Updated to NodeBB v4.3 + New Features

How to get keyboard input PS/2 scan codes or USB usage codes in Linux?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Twinky
    wrote on 21 Jan 2013, 02:31 last edited by
    #1

    Hello,

    I'm trying to get the PS/2 scan codes or USB usage codes of keyboard keys pressed in a Qt application running on Linux. I tried overriding "QWidget::keyPressEvent()":http://qt-project.org/doc/qt-4.8/qwidget.html#keyPressEvent but "QKeyEvent::navtiveScanCode()":http://qt-project.org/doc/qt-4.8/qkeyevent.html#nativeScanCode returns a value which doesn't correspond to the key's equilvalent PS/2 Set 1, Set 2, or Set 3 scan code nor the USB usage code. Instead, I believe this function returns a X11 mapped keycode.

    Example: the 'a' key returns 0x26 instead of 0x1E (PS/2 Set 1) or 0x1C (Set 2 & 3) or 0x04 (USB).

    This occurs even if I try to intercept the key at the X11 event loop "QWidget::x11Event(":http://qt-project.org/doc/qt-4.8/qwidget.html#x11Event). In this case, "XKeyPressedEvent::keycode":http://www.x.org/releases/X11R7.6/doc/libX11/specs/libX11/libX11.html#Keyboard_and_Pointer_Events_b also equals to 0x26 for the 'a' key.

    However, the terminal commands "showkey -k":http://linux.die.net/man/1/showkey and "showkey -s":http://linux.die.net/man/1/showkey both show the 'a' key to be equal to 0x1E as expected.

    How do I get the PS/2 scan code or the USB usage code for key presses?

    OS: Fedora 17 x86
    X Server: 1.12.4
    X Protocol: 11 rev0
    Qt: 4.8.4

    Regards,
    Daniel K.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on 21 Jan 2013, 22:12 last edited by
      #2

      If your just looking to look for keypresses, then the keyboard event that you described in the beginning is definitely what you want.

      The keypress override returns the Qt key "type", which basically is a bunch of enumerated keyboard presses. For example: Qt::Key_A is the A key.

      Check the key pressed like this:
      @
      QWidget::keyPressEvent ( QKeyEvent * event )
      {
      switch(event->key()){
      case Qt::Key_a:
      break;
      default:
      break;
      }
      }
      @

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Twinky
        wrote on 22 Jan 2013, 07:07 last edited by
        #3

        [quote author="dvez43" date="1358806327"]If your just looking to look for keypresses, then the keyboard event that you described in the beginning is definitely what you want.[/quote]

        It's not keypresses I'm after, it's the scan code the keyboard emits. Either the scan code conforming to the PS/2 or USB specification.

        [quote author="dvez43" date="1358806327"]The keypress override returns the Qt key “type”, which basically is a bunch of enumerated keyboard presses. For example: Qt::Key_A is the A key.[/quote]

        I tried out QKeyEvent::key() but it is not what I'm looking for because those returned values don't conform to either the PS/2 or USB specifications. For example, the 'a' key returns 0x41.

        1 Reply Last reply
        0

        1/3

        21 Jan 2013, 02:31

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved