Esempio n. 1
0
void QvkShowkeyGetkey::run()
{
  const timespec sleeptime = { 0, 1000000 };

  /*
   * open the display
   */
  if (! ( display = XOpenDisplay( NULL ) ) )
  {
    std::cerr << "Can't open display NULL" << '\n';
    std::exit(1);
  }

  /*
   * fill up keyboard mapping
   */
  
  //fill_mappings();
  
  // keys aus eigene Routine ermitteln
  QStringList keyList = PrintKeyTable();
  

  /*
   * fill relevant key buffers
   */
  char keys[32];                  // buffer for reading keys in
  char lastkeys[32];              // previous keys state  

  std::fill(lastkeys, lastkeys + sizeof(lastkeys), 0);
		
  /*
   * query keyboard in loop
   */
  bool last_is_nav  = false;    // navigation key indicator
//  bool last_is_char = false;    // spaces adjustment
  while (cont) {
    nanosleep(&sleeptime, 0);   // avoid busy waiting
    
    XQueryKeymap( display, keys );
    
    // read modifiers (caps lock is ignored)
    bool shift = false;
    bool ctrl  = false;
    bool alt   = false;
    bool meta  = false;

    for (unsigned i = 0; i < sizeof(keys); ++i)
      for (unsigned j = 0, test = 1; j < 8; ++j, test *= 2)
        if (keys[i] & test)
	{
          const int code = i*8+j;

          if (shift_set.find(code) != shift_set.end())
	  {
            shift = true;
	    qDebug() << "Shift = true";
	  }
	  
          if (ctrl_set.find(code) != ctrl_set.end())
            ctrl = true;

          if (alt_set.find(code) != alt_set.end())
            alt = true;

          if (meta_set.find(code) != meta_set.end())
            meta = true;
	  
        }
    
    // print changed keys
    for (unsigned i = 0; i < sizeof(keys); ++i)
      if (keys[i] != lastkeys[i]) {
        // check which key got changed
        for (unsigned j = 0, test = 1; j < 8; ++j, test *= 2)
          // if the key was pressed, and it wasn't before, print this
          if ((keys[i] & test) && ((keys[i] & test) != (lastkeys[i] & test)))
	  {
            const int code = i*8+j;
            QString key = getKey( keyList, code );

            const bool key_is_nav = ( key == "Nav" );

            // only print navigation keys once
            if ( ! (last_is_nav && key_is_nav) && key.size() > 0 )
	    {
              // change key according to modifiers
              if ( ! key_is_nav)
	      {
		if ( meta )
                  key = " Meta-" + key + " ";

                if ( alt )
                  key = " Alt-" + key + " ";

                if ( ctrl )
                  key = " Ctrl-" + key + " ";

	        if ( ( not shift ) )
	        {
	          emit pressedKey( key );
	        }
		
		// shift
                if ( shift )
		{
                  emit pressedKey( getKeyShift( keyList, code ) );
		}
		
              }
	      
              last_is_nav = key_is_nav;
            }
          }
      
        lastkeys[i] = keys[i];
      }
  }

  XCloseDisplay(display);
}
Esempio n. 2
0
void 
print_key_table(Bool exprs)
{
    PrintKeyTable (exprs, stdout);
    return;
}