自定义4*4矩阵键盘在Qt4程序中的使用方法 矩阵键盘扫描程序

解压qt-everywhere-opensource-src-4.7.0.tgz到当前目录。

1. 修改qt-everywhere-opensource-src-4.7.0/src/gui/embedded/src/gui/embedded/qkbdtty_qws.h,其内容如下:
#ifndef QKBDTTY_QWS_H

#define QKBDTTY_QWS_H

#include<QtGui/qkbd_qws.h>

#ifndef QT_NO_QWS_KEYBOARD

#ifndef QT_NO_QWS_KBD_TTY

class QWSMyKbPrivate;

class QWSMyKeyboardHandler : publicQWSKeyboardHandler

{

public:

QWSMyKeyboardHandler(const QString&);

virtual ~QWSMyKeyboardHandler();

private:

QWSMyKbPrivate *d;

};

#endif // QT_NO_QWS_KBD_TTY

#endif // QT_NO_QWS_KEYBOARD

#endif // QKBDTTY_QWS_H

2. 修改qt-everywhere-opensource-src-4.7.0/src/gui/embedded/qkbdtty_qws.cpp,其内容如下:

#include "qkbdtty_qws.h"

#if !defined(QT_NO_QWS_KEYBOARD)&& !defined(QT_NO_QWS_KBD_TTY)

#include<sys/types.h>

#include<sys/stat.h>

#include<sys/ioctl.h>

#include<fcntl.h>

#include<termios.h>

#include<unistd.h>

#include<errno.h>

#include<private/qcore_unix_p.h>

#include<qsocketnotifier.h>

class QWSMyKbPrivate : publicQObject

{

Q_OBJECT

public:

QWSMyKbPrivate(QWSMyKeyboardHandler*handler, const QString &device);

~QWSMyKbPrivate();

bool isOpen() { return buttonFD> 0; }

private Q_SLOTS:

void readKeyboardData();

private:

QWSMyKeyboardHandler *m_handler;

QString terminalName;

int buttonFD;

int kbdIdx;

int kbdBufferLen;

unsigned char *kbdBuffer;

QSocketNotifier *notifier;

};

QWSMyKeyboardHandler::QWSMyKeyboardHandler(const QString&device)

: QWSKeyboardHandler(device)

{

d = new QWSMyKbPrivate(this,device);

}

QWSMyKeyboardHandler::~QWSMyKeyboardHandler()

{

delete d;

}

QWSMyKbPrivate::QWSMyKbPrivate(QWSMyKeyboardHandler *h, constQString &device)

: m_handler(h)

{

terminalName =device.isEmpty()?"/dev/atao_button":device.toLatin1();

buttonFD = -1;

notifier = 0;

if ((buttonFD =QT_OPEN(terminalName.toLatin1().constData(), O_RDONLY | O_NDELAY))< 0)

{

qWarning("Cannot open %sn",terminalName.toLatin1());

}

printf("open /dev/atao_buttonOK!tbuttonFD=%dn",buttonFD);

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;

}

QWSMyKbPrivate::~QWSMyKbPrivate()

{

if ( buttonFD > 0)

{

::close( buttonFD );

buttonFD = -1;

}

delete notifier;

notifier = 0;

delete [] kbdBuffer;;

}

voidQWSMyKbPrivate::readKeyboardData()

{

int n = 0;

int idx = 0;

n = read(buttonFD, kbdBuffer+kbdIdx,4);

unsigned char *next = kbdBuffer +idx;

int *code = (int *)next;

int keycode = Qt::Key_unknown;

int unicode = 0;

switch ( (*code) &0xff )

{

case 0:

keycode = Qt::Key_0;

unicode='0';

break;

case 1:

keycode = Qt::Key_1;

unicode='1';

break;

case 2:

keycode = Qt::Key_2;

unicode='2';

break;

case 3:

keycode = Qt::Key_3;

unicode='3';

break;

case 4:

keycode = Qt::Key_4;

unicode='4';

break;

case 5:

keycode = Qt::Key_5;

unicode='5';

break;

case 6:

keycode = Qt::Key_6;

unicode='6';

break;

case 7:

keycode = Qt::Key_7;

unicode='7';

break;

case 8:

keycode = Qt::Key_8;

unicode='8';

break;

case 9:

keycode = Qt::Key_9;

unicode='9';

break;

case 10:

keycode = Qt::Key_Enter;

break;

case 11:

keycode = Qt::Key_Escape;

break;

case 12:

keycode = Qt::Key_Tab;

break;

case 13:

keycode = Qt::Key_Backspace;

break;

case 14:

keycode = Qt::Key_Right;

break;

case 15:

keycode = Qt::Key_Left;

break;

default:

qDebug("Unrecognised key code %d",*code );

}

m_handler->processKeyEvent( unicode, keycode, 0,TRUE, FALSE );

m_handler->processKeyEvent( unicode, keycode, 0,FALSE, FALSE);

//m_handler->processKeyEvent( 0, keycode, 0, TRUE,FALSE );

}

#include "qkbdtty_qws.moc"

#endif // QT_NO_QWS_KEYBOARD ||QT_NO_QWS_KBD_TTY

注意,此处,我的键盘驱动设备为/dev/atao_button,使用了4*4矩阵键盘,定义如下图,所要,要先写好键盘驱动啦。





3. 在 qt-everywhere-opensource-src-4.7.0目录中运行如下configure 命令

./configure -prefix/usr/src/qt470arm.kb.4.2.2 -opensource -confirm-license -release-shared -embedded arm -xplatform qws/linux-arm-g++ -no-qt3support-fast -no-largefile -make tools -make demos -make examples -makedocs -qt-libjpeg -qt-libpng -qt-libtiff -qt-gif -multimedia

4. make & make install
自定义4*4矩阵键盘在Qt4程序中的使用方法 矩阵键盘扫描程序

重新grep "QWSMyKeyboardHandler" * -R会得到如下结果表明添加自定义按键驱动成功

ttseibm@ttseibm-T60:~/qt-everywhere-opensource-src-4.7.0$ grep"QWSMyKeyboardHandler" * -R

Binary file lib/libQtGui.so.4.7matches

Binary file lib/libQtGui.somatches

Binary file lib/libQtGui.so.4.7.0matches

Binary file lib/libQtGui.so.4matches

src/gui/embedded/qkbdtty_qws.h:classQWSMyKeyboardHandler : public QWSKeyboardHandler

src/gui/embedded/qkbdtty_qws.h:QWSMyKeyboardHandler(const QString &);

src/gui/embedded/qkbdtty_qws.h:virtual ~QWSMyKeyboardHandler();

src/gui/embedded/qkbdtty_qws.cpp:QWSMyKbPrivate(QWSMyKeyboardHandler *handler, const QString&device);

src/gui/embedded/qkbdtty_qws.cpp:QWSMyKeyboardHandler *m_handler;

src/gui/embedded/qkbdtty_qws.cpp:QWSMyKeyboardHandler::QWSMyKeyboardHandler(constQString &device)

src/gui/embedded/qkbdtty_qws.cpp:QWSMyKeyboardHandler::~QWSMyKeyboardHandler()

src/gui/embedded/qkbdtty_qws.cpp:QWSMyKbPrivate::QWSMyKbPrivate(QWSMyKeyboardHandler*h, const QString &device)

src/gui/embedded/qkbddriverfactory_qws.cpp: return newQWSMyKeyboardHandler(device);

Binary filesrc/gui/embedded/backup.tar matches

Binary filesrc/gui/.obj/release-shared-emb-arm/qkbddriverfactory_qws.omatches

Binary filesrc/gui/.obj/release-shared-emb-arm/qkbdtty_qws.o matches

ttseibm@ttseibm-T60:~/qt-everywhere-opensource-src-4.7.0$

5. 用Qt SDK 开发程序啦。。

  

爱华网本文地址 » http://www.aihuau.com/a/25101010/42428.html

更多阅读

在家里灭蟑螂的好方法 家里怎样灭蟑螂

在家里灭蟑螂的好方法——简介怎么灭蟑螂呢?相信很多人都很烦这种昆虫,甚至有的人看到蟑螂还会觉得恶心,下面就介绍给大家在家里灭蟑螂的好方法!在家里灭蟑螂的好方法——工具/原料灭蟑螂的药物,开水,扫帚在家里灭蟑螂的好方法——方法/

竞争情报的价值---情报在企业决策中的作用 生意参谋竞争情报

竞争情报在企业决策中的作用据了解,在20世纪80年代,世界500强中有10%建立了竞争情报系统;90年代已有80%以上建立了竞争情报系统;现阶段,500强中已经有90%以上的公司建立了竞争情报系统,竞争情报在企业中的应用表现出了强劲的生命力和蓬勃发

C5 石油树脂改性及其在路标漆中的应用 c5加氢石油树脂

C5 石油树脂改性及其在路标漆中的应用于洪波, 丛玉凤*, 廖克俭, 张玲, 孙凤娇(辽宁石油化工大学化学材料学院,辽宁抚顺113001)前言目前我国公路迅猛发展,为路标漆提供了广阔的市场。路标漆主要有热熔型和自干型[1 ]。由于树脂来源充足,价格不

声明:《自定义4*4矩阵键盘在Qt4程序中的使用方法 矩阵键盘扫描程序》为网友含笑自然分享!如侵犯到您的合法权益请联系我们删除