⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qkeyboard_qws.cpp

📁 qte2.3.2版本,但是里面没有configure文件.需要重新添加
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	    repeat = TRUE;	processKeyEvent( unicode, keyCode, modifiers, !release, repeat );	if (!release) {	    prevuni = unicode;	    prevkey = keyCode;	} else {	    prevkey = prevuni = 0;	}    }    extended = false;}//// Tty keyboard//QWSTtyKeyboardHandler::QWSTtyKeyboardHandler(){    kbdFD=open("/dev/tty0", O_RDWR | O_NDELAY, 0);    if ( kbdFD >= 0 ) {	QSocketNotifier *notifier;	notifier = new QSocketNotifier( kbdFD, QSocketNotifier::Read, this );	connect( notifier, SIGNAL(activated(int)),this,		 SLOT(readKeyboardData()) );    }    // save for restore.    tcgetattr( kbdFD, &origTermData );    struct termios termdata;    tcgetattr( kbdFD, &termdata );#if !defined(_OS_FREEBSD_)    ioctl(kbdFD, KDSKBMODE, K_RAW);#endif    termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);    termdata.c_oflag = 0;    termdata.c_cflag = CREAD | CS8;    termdata.c_lflag = 0;    termdata.c_cc[VTIME]=0;    termdata.c_cc[VMIN]=1;    cfsetispeed(&termdata, 9600);    cfsetospeed(&termdata, 9600);    tcsetattr(kbdFD, TCSANOW, &termdata);    signal(VTSWITCHSIG, vtSwitchHandler);#if !defined(_OS_FREEBSD_)    struct vt_mode vtMode;    ioctl(kbdFD, VT_GETMODE, &vtMode);    // let us control VT switching    vtMode.mode = VT_PROCESS;    vtMode.relsig = VTSWITCHSIG;    vtMode.acqsig = VTSWITCHSIG;    ioctl(kbdFD, VT_SETMODE, &vtMode);    struct vt_stat vtStat;    ioctl(kbdFD, VT_GETSTATE, &vtStat);    vtQws = vtStat.v_active;#endif}QWSTtyKeyboardHandler::~QWSTtyKeyboardHandler(){    if (kbdFD >= 0)    {#if !defined(_OS_FREEBSD_)	ioctl(kbdFD, KDSKBMODE, K_XLATE);#endif	tcsetattr(kbdFD, TCSANOW, &origTermData);	::close(kbdFD);	kbdFD = -1;    }}void QWSTtyKeyboardHandler::readKeyboardData(){    unsigned char buf[81];    int n = read(kbdFD, buf, 80 );    for ( int loop = 0; loop < n; loop++ )	doKey(buf[loop]);}/* USB driver */QWSUsbKeyboardHandler::QWSUsbKeyboardHandler(){    fd = open(getenv("QWS_USB_KEYBOARD"),O_RDONLY, 0);    if ( fd >= 0 ) {	QSocketNotifier *notifier;	notifier = new QSocketNotifier( fd, QSocketNotifier::Read, this );	connect( notifier, SIGNAL(activated(int)),this,		 SLOT(readKeyboardData()) );    }}QWSUsbKeyboardHandler::~QWSUsbKeyboardHandler(){    close(fd);}struct Myinputevent {    unsigned int dummy1;    unsigned int dummy2;    unsigned short type;    unsigned short code;    unsigned int value;};void QWSUsbKeyboardHandler::readKeyboardData(){    Myinputevent event;    int n = read(fd, &event, sizeof(Myinputevent) );    if ( n != 16 )	return;    int key=event.code;    if(key==103) {	processKeyEvent( 0, Qt::Key_Up, 0, event.value!=0, false );    } else if(key==106) {	processKeyEvent( 0, Qt::Key_Right, 0, event.value!=0, false  );    } else if(key==108) {	processKeyEvent( 0, Qt::Key_Down, 0, event.value!=0, false );    } else if(key==105) {	processKeyEvent( 0, Qt::Key_Left, 0, event.value!=0, false );    } else {	if(event.value==0) {	    key=key | 0x80;	}	doKey(key);    }}/* * YOPY buttons driver * Contributed by Ron Victorelli (victorrj at icubed.com) */QWSyopyButtonsHandler::QWSyopyButtonsHandler() : QWSKeyboardHandler(){#ifdef QT_QWS_YOPY    terminalName = "/dev/tty1";    buttonFD = -1;    notifier = 0;    if ((buttonFD = open(terminalName, O_RDWR | O_NDELAY, 0)) < 0) {	qFatal("Cannot open %s\n", terminalName.latin1());    } else {       tcsetpgrp(buttonFD, getpgid(0));       /* put tty into "straight through" mode.       */       if (tcgetattr(buttonFD, &oldT) < 0) {           qFatal("Linux-kbd: tcgetattr failed");       }       newT = oldT;       newT.c_lflag &= ~(ICANON | ECHO  | ISIG);       newT.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);       newT.c_iflag |= IGNBRK;       newT.c_cc[VMIN]  = 0;       newT.c_cc[VTIME] = 0;       if (tcsetattr(buttonFD, TCSANOW, &newT) < 0) {           qFatal("Linux-kbd: TCSANOW tcsetattr failed");       }       if (ioctl(buttonFD, KDSKBMODE, K_MEDIUMRAW) < 0) {           qFatal("Linux-kbd: KDSKBMODE tcsetattr failed");       }	notifier = new QSocketNotifier( buttonFD, QSocketNotifier::Read, this );	connect( notifier, SIGNAL(activated(int)),this,		 SLOT(readKeyboardData()) );    }#endif}QWSyopyButtonsHandler::~QWSyopyButtonsHandler(){#ifdef QT_QWS_YOPY    if ( buttonFD > 0 ) {	::close( buttonFD );	buttonFD = -1;    }#endif}void QWSyopyButtonsHandler::readKeyboardData(){#ifdef QT_QWS_YOPY    uchar buf[1];    char c='1';    int fd;    int n=read(buttonFD,buf,1);    if (n<0) {	qDebug("Keyboard read error %s",strerror(errno));    } else {	uint code = buf[0]&YPBUTTON_CODE_MASK;        bool press = !(buf[0]&0x80);        // printf("Key=%d/%d/%d\n",buf[1],code,press);        int k=(-1);        switch(code) {          case 39:       k=Qt::Key_Up;     break;          case 44:       k=Qt::Key_Down;   break;          case 41:       k=Qt::Key_Left;   break;          case 42:       k=Qt::Key_Right;  break;          case 56:       k=Qt::Key_F1;     break; //windows          case 29:       k=Qt::Key_F2;     break; //cycle          case 24:       k=Qt::Key_F3;     break; //record          case 23:       k=Qt::Key_F4;     break; //mp3          case 4:        k=Qt::Key_F5;     break; // PIMS          case 1:        k=Qt::Key_Escape; break; // Escape          case 40:       k=Qt::Key_Up;     break; // prev          case 45:       k=Qt::Key_Down;   break; // next          case 35:       if( !press ) {                           fd = open("/proc/sys/pm/sleep",O_RDWR,0);                           if( fd >= 0 ) {                               write(fd,&c,sizeof(c));                               close(fd);                               //                               // Updates all widgets.                               //                               QWidgetList  *list = QApplication::allWidgets();                               QWidgetListIt it( *list );          // iterate over the widgets                               QWidget * w;                               while ( (w=it.current()) != 0 ) {   // for each widget...                                 ++it;                                 w->update();                               }                               delete list;                               // qApp->desktop()->repaint();                           }                         }                         break;          default: k=(-1); break;        }	if ( k >= 0 ) {		qwsServer->processKeyEvent( 0, k, 0, press, false );	}    }#endif}/* * vr41xx buttons driver */QWSVr41xxButtonsHandler::QWSVr41xxButtonsHandler() : QWSKeyboardHandler(){#ifdef QT_QWS_CASSIOPEIA    terminalName = "/dev/buttons";    buttonFD = -1;    notifier = 0;    if ((buttonFD = open(terminalName, O_RDWR | O_NDELAY, 0)) < 0)    {	qWarning("Cannot open %s\n", terminalName.latin1());    }    if ( buttonFD >= 0 ) {	notifier = new QSocketNotifier( buttonFD, QSocketNotifier::Read, this );	connect( notifier, SIGNAL(activated(int)),this,		 SLOT(readKeyboardData()) );    }    kbdBufferLen = 80;    kbdBuffer = new unsigned char [kbdBufferLen];    kbdIdx = 0;#endif}QWSVr41xxButtonsHandler::~QWSVr41xxButtonsHandler(){#ifdef QT_QWS_CASSIOPEIA    if ( buttonFD > 0 ) {	::close( buttonFD );	buttonFD = -1;    }    delete notifier;    notifier = 0;    delete [] kbdBuffer;#endif}void QWSVr41xxButtonsHandler::readKeyboardData(){#ifdef QT_QWS_CASSIOPEIA    int n = 0;    do {	n  = read(buttonFD, kbdBuffer+kbdIdx, kbdBufferLen - kbdIdx );	if ( n > 0 )	    kbdIdx += n;    } while ( n > 0 );    int idx = 0;    while ( kbdIdx - idx >= 2 ) {	unsigned char *next = kbdBuffer + idx;	unsigned short *code = (unsigned short *)next;	int keycode = Qt::Key_unknown;	switch ( (*code) & 0x0fff ) {	    case 0x7:		keycode = Qt::Key_Up;		break;	    case 0x9:		keycode = Qt::Key_Right;		break;	    case 0x8:		keycode = Qt::Key_Down;		break;	    case 0xa:		keycode = Qt::Key_Left;		break;	    case 0x3:		keycode = Qt::Key_Up;		break;	    case 0x4:		keycode = Qt::Key_Down;		break;	    case 0x1:		keycode = Qt::Key_Return;		break;	    case 0x2:		keycode = Qt::Key_F4;		break;	    default:		qDebug("Unrecognised key sequence %d", (int)code );	}	if ( (*code) & 0x8000 )	    processKeyEvent( 0, keycode, 0, FALSE, FALSE );	else	    processKeyEvent( 0, keycode, 0, TRUE, FALSE );/*	unsigned short t = *code;	for ( int i = 0; i < 16; i++ ) {	    keycode = (t & 0x8000) ? Qt::Key_1 : Qt::Key_0;	    int unicode = (t & 0x8000) ? '1' : '0';	    processKeyEvent( unicode, keycode, 0, TRUE, FALSE );	    processKeyEvent( unicode, keycode, 0, FALSE, FALSE );	    t <<= 1;	}	keycode = Qt::Key_Space;//	processKeyEvent( ' ', keycode, 0, TRUE, FALSE );//	processKeyEvent( ' ', keycode, 0, FALSE, FALSE );*/	idx += 2;    }    int surplus = kbdIdx - idx;    for ( int i = 0; i < surplus; i++ )	kbdBuffer[i] = kbdBuffer[idx+i];    kbdIdx = surplus;#endif}/* * Virtual framebuffer keyboard driver */#ifndef QT_NO_QWS_VFB#include "qvfbhdr.h"extern int qws_display_id;#endifQWSVFbKeyboardHandler::QWSVFbKeyboardHandler(){    kbdFD = -1;#ifndef QT_NO_QWS_VFB    kbdIdx = 0;    kbdBufferLen = sizeof( QVFbKeyData ) * 5;    kbdBuffer = new unsigned char [kbdBufferLen];    terminalName = QString(QT_VFB_KEYBOARD_PIPE).arg(qws_display_id);    if ((kbdFD = open( terminalName.local8Bit(), O_RDWR | O_NDELAY)) < 0) {	qDebug( "Cannot open %s (%s)", terminalName.latin1(),	strerror(errno));    } else {	// Clear pending input	char buf[2];	while (read(kbdFD, buf, 1) > 0) { }	notifier = new QSocketNotifier( kbdFD, QSocketNotifier::Read, this );	connect(notifier, SIGNAL(activated(int)),this, SLOT(readKeyboardData()));    }#endif}QWSVFbKeyboardHandler::~QWSVFbKeyboardHandler(){#ifndef QT_NO_QWS_VFB    if ( kbdFD >= 0 )	close( kbdFD );    delete [] kbdBuffer;#endif}void QWSVFbKeyboardHandler::readKeyboardData(){#ifndef QT_NO_QWS_VFB    int n;    do {	n  = read(kbdFD, kbdBuffer+kbdIdx, kbdBufferLen - kbdIdx );	if ( n > 0 )	    kbdIdx += n;    } while ( n > 0 );    int idx = 0;    while ( kbdIdx - idx >= (int)sizeof( QVFbKeyData ) ) {	QVFbKeyData *kd = (QVFbKeyData *)(kbdBuffer + idx);	if ( kd->unicode == 0 && kd->modifiers == 0 && kd->press ) {	    // magic exit key	    qWarning( "Instructed to quit by Virtual Keyboard" );	    qApp->quit();	}	processKeyEvent( kd->unicode&0xffff, kd->unicode>>16,				 kd->modifiers, kd->press, kd->repeat );	idx += sizeof( QVFbKeyData );    }    int surplus = kbdIdx - idx;    for ( int i = 0; i < surplus; i++ )	kbdBuffer[i] = kbdBuffer[idx+i];    kbdIdx = surplus;#endif}/* * keyboard driver instantiation */QWSKeyboardHandler *QWSServer::newKeyboardHandler( const QString &spec ){    QWSKeyboardHandler *handler = 0;    if ( spec == "Buttons" ) {#if defined(QT_QWS_YOPY)	handler = new QWSyopyButtonsHandler();#elif defined(QT_QWS_CASSIOPEIA)	handler = new QWSVr41xxButtonsHandler();#endif    } else if ( spec == "QVFbKeyboard" ) {	handler = new QWSVFbKeyboardHandler();    } else if ( spec == "TTY" ) {	if(getenv("QWS_USB_KEYBOARD")) {	    handler = new QWSUsbKeyboardHandler();	} else {	    handler = new QWSTtyKeyboardHandler();	}    } else {	qWarning( "Keyboard type %s unsupported", spec.latin1() );    }    return handler;}#include "qkeyboard_qws.moc"#ifdef QT_QWS_PSION#define QT_QWS_IPAQ//#undef QT_QWS_CUSTOM#endif#endif // QNX6const QWSServer::KeyMap *QWSServer::keyMap(){    return keyM;}#endif // QT_NO_QWS_KEYBOARD

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -