• 大小: 4KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-07
  • 语言: 其他
  • 标签: QT  keypad  

资源简介

使用QT编写的键盘,全键盘,有大小写切换,输入数字,标点符号,能够完成在arm板上开发用

资源截图

代码片段和文件信息


#include 
#include 
#include 
#include “keytest.h“
#include “ui_keytest.h“

Keytest::Keytest(QWidget *parent) :
    QWidget(parent)
    ui(new Ui::Keytest)

{
     ui->setupUi(this);
     m_fd = open(::getenv(“KEYPAD_DEV“) O_RDONLY | O_NONBLOCK);

     if (m_fd < 0)
     {
         QMessageBox::information(this“Error“ “Fail to open Please check your key  device“);
         return;
     }

     memset(m_oldButtonsState 0 sizeof(m_oldButtonsState));
     m_notifyobject = new QSocketNotifier(m_fd QSocketNotifier::Read this);
     connect (m_notifyobject SIGNAL(activated(int)) this SLOT(keyEvent()));
}

Keytest::~Keytest()
{
     delete m_notifyobject;
     ::close(m_fd);
     delete ui;
}

void Keytest::keyEvent()
{
      char buffer[KEYMAXNUM];
      memset(buffer 0 sizeof(buffer));
      struct InputData  event;
      int nResult=::read(m_fd &event sizeof(event));
      if (nResult !=  sizeof(InputData))
      {
          QMessageBox::information(this“Debug““read error“);
          return;
      }
      switch(event.code)
      {
          case KEY_UP:
              buffer[0]=event.value;
              break;
          case KEY_DOWN:
              buffer[1]=event.value;
              break;
          case KEY_LEFT:
              buffer[2]=event.value;
              break;
          case KEY_RIGHT:
              buffer[3]=event.value;
              break;
          case KEY_ENTER:
              buffer[4]=event.value;
              break;
          case KEY_ESC:
              buffer[5]=event.value;
              break;
          default:
              break;
      }

      for (unsigned i = 0; i < sizeof(buffer) / sizeof(buffer[0]); i++)
      {
             bool oldState = m_oldButtonsState[i];
             bool isOn = (buffer[i] & 0x01);

            if (oldState != isOn)
            {
               m_oldButtonsState[i] = isOn;
               update();  //this function will call paintEvent
            }
      }

}


void Keytest::paintEvent(QPaintEvent*)
{
    for(unsigned i=0;i    {
        if(m_oldButtonsState[i])
        {
            switch(i)
            {
                case 0://up
                    ui->pbt_up ->setstyleSheet(QString::fromUtf8(“background-color: rgb(0 0 255);“));
                break;

                case 1://down
                     ui->pbt_down->setstyleSheet(QString::fromUtf8(“background-color: rgb(0 0 255);“));
                break;

                case 2://left
                     ui->pbt_left->setstyleSheet(QString::fromUtf8(“background-color: rgb(0 0 255);“));
                break;

                case 3://right
                     ui->pbt_right->setstyleSheet(QString::fromUtf8(“background-color: rgb(0 0 255);“));
                break;

                case 4://enter
                     ui->pbt_enter->setstyleSheet(QString::fromUtf8(“background-color: rgb(0 0 255);“));
                break;

                case 5:/

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        351  2013-11-12 10:25  keypad\keypad.pro

     文件       7959  2014-05-13 11:52  keypad\keypad.pro.user

     文件       4676  2013-11-12 10:25  keypad\keytest.cpp

     文件       1216  2013-11-12 10:25  keypad\keytest.h

     文件       2462  2013-11-12 10:25  keypad\keytest.ui

     文件        286  2013-11-12 10:25  keypad\main.cpp

     目录          0  2014-09-09 11:45  keypad

----------- ---------  ---------- -----  ----

                16950                    7


评论

共有 条评论