c进程读取按键输入,通过socket传输给qt,qt按键线程接收到后,提交到Qt的事件处理系统中
2015-05-07 17:16
686 查看
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
#include <QCoreApplication>
#include <QMouseEvent>
#include <QTimer>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
protected:
private slots:
void ZSlotMove();
void ZSlotOkay();
void ZSlotBtn1();
void ZSlotBtn2();
void ZSlotBtn3();
void ZSlotBtn4();
void ZSlotTimeout();
private:
Ui::Widget *ui;
QTimer *m_timer;
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->btn1->setFocusPolicy(Qt::StrongFocus);
ui->btn2->setFocusPolicy(Qt::StrongFocus);
ui->btn3->setFocusPolicy(Qt::StrongFocus);
ui->btn4->setFocusPolicy(Qt::StrongFocus);
ui->btnMove->setFocusPolicy(Qt::StrongFocus);
ui->btnOkay->setFocusPolicy(Qt::StrongFocus);
connect(ui->btn1,SIGNAL(clicked()),this,SLOT(ZSlotBtn1()));
connect(ui->btn2,SIGNAL(clicked()),this,SLOT(ZSlotBtn2()));
connect(ui->btn3,SIGNAL(clicked()),this,SLOT(ZSlotBtn3()));
connect(ui->btn4,SIGNAL(clicked()),this,SLOT(ZSlotBtn4()));
connect(ui->btnMove,SIGNAL(clicked()),this,SLOT(ZSlotMove()));
connect(ui->btnOkay,SIGNAL(clicked()),this,SLOT(ZSlotOkay()));
ui->btn1->setFocus();
this->m_timer=new QTimer;
connect(this->m_timer,SIGNAL(timeout()),this,SLOT(ZSlotTimeout()));
this->m_timer->start(1000);
}
Widget::~Widget()
{
delete ui;
}
void Widget::ZSlotTimeout()
{
QWidget *tCurFocsWidget=QApplication::focusWidget();
if(tCurFocsWidget)
{
//post a tab key to change the current widget.
QKeyEvent *tTabKeyPress=new QKeyEvent( QEvent::KeyPress,Qt::Key_Tab,Qt::NoModifier);
QApplication::postEvent(tCurFocsWidget,tTabKeyPress);
//generate a mouse press and mouse release event.
QMouseEvent *tMousePress=new QMouseEvent(QEvent::MouseButtonPress,QPoint(2,2),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QApplication::postEvent(tCurFocsWidget->focusWidget(),tMousePress);
QMouseEvent *tMouseRelease=new QMouseEvent(QEvent::MouseButtonRelease,QPoint(2,2),Qt::LeftButton,Qt::NoButton,Qt::NoModifier);
QApplication::postEvent(tCurFocsWidget->focusWidget(),tMouseRelease);
}else{
qDebug()<<"no global focus widget";
}
}
void Widget::ZSlotMove()
{
qDebug()<<"move button was clicked:";
}
void Widget::ZSlotOkay()
{
qDebug()<<"okay button was clicked:";
}
void Widget::ZSlotBtn1()
{
qDebug()<<"button1 was clicked:";
}
void Widget::ZSlotBtn2()
{
qDebug()<<"button2 was clicked:";
}
void Widget::ZSlotBtn3()
{
qDebug()<<"button3 was clicked:";
}
void Widget::ZSlotBtn4()
{
qDebug()<<"button4 was clicked:";
}
刚试验出来,奶奶的不容易呀。
设备上有几个按键,写一个c程序用于不断的读取按键的,泥玛,没有接到中断上,只好每隔100ms读一次,真服了画板的人。
上下左右,用于移动光标,
这里暂时只实现了模拟Tab按键,一直向下,应该加上向左向右,等功能。
确定按键就是postEvent一个鼠标左键的Press和Release一对值就可以了。
相关文章推荐
- 通过给事件处理程序传递this参数,获取事件源对象的引用。单机提交按钮时在信息框中显示用户输入的字符。
- 系统在处理一些 I/O 事件或磁盘读取时会动态提升相应线程的优先级
- Qt 处理键盘按键事件:只能输入字母 keyPressEvent
- gdb动态库延迟断点及线程/进程创建相关事件处理(上)
- gdb动态库延迟断点及线程/进程创建相关事件处理(
- gdb动态库延迟断点及线程/进程创建相关事件处理(下)
- vc/mfc 进程消息队列,线程消息队列,和系统消息队列,该如何处理
- 通过代码调整系统音量,监听音量实体按键事件
- Android输入事件从读取到分发三:InputDispatcherThread线程分发事件的过程
- 通过form的action属性提交表单并接收处理返回值的方法(页面不跳转)
- 通过adb发送按键输入事件
- android学生管理系统,利用linerLayout,实现xml的读取和写入,以及按钮的事件处理
- QTcpSocket 不通过事件,直接等待获取数据结果
- 通过系统自带的内容提供器(ContentResolver)读取系统的通讯录,并设置点击事件
- [Q学习]10 Qt事件系统——处理事件
- Android系统--输入系统(十四)Dispatcher线程情景分析_dispatch前处理
- Input事件输入系统之应用MotionEvent触摸事件处理流程
- QT事件处理,鼠标事件,按键键盘事件,定时器,进度条。
- Android输入事件从读取到分发三:InputDispatcherThread线程分发事件的过程
- C# winform端 通过HttpWebRequest进行post和get请求,数据格式为json,后台java端接收,其中有关传输特殊字符(\t,\r,',\n,n)等处理