Commit 9338109c by xiaojing.zhang

1.hook BUG 修复

parent 682c7bba
......@@ -238,18 +238,8 @@ bool NavWindow::eventFilter(QObject *target, QEvent *event)
}
if (event->type() == NOCODE_EVENT)
{
FMP_INFO()<< "home navwindow got message to clear the hooked data event";
// qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch();
//if(timestamp - _timestamp >200 )
// {
QTimer::singleShot(300,this,SLOT(timercall()));
//}
//_timestamp = timestamp;
//FMP_INFO()<< "home navwindow got message to clear the hooked data event";
QTimer::singleShot(30,this,SLOT(timercall()));
return true;
......
......@@ -9,11 +9,18 @@ qint64 KeyboardListener::_forDataStamp = 0;
QLineEdit *KeyboardListener::up = 0;
std::string KeyboardListener::_QCode = "";
std::string KeyboardListener::_retCode = "";
std::string KeyboardListener::_numToDistri = "";
std::string _test="";
bool _sign =true;
Qt::KeyboardModifiers KeyboardListener::curModifiers = Qt::NoModifier;
KeyboardListener::KeyboardListener()
{
ahook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)recordListener, 0, 0);
// test = "";
}
......@@ -22,6 +29,8 @@ LRESULT CALLBACK KeyboardListener::recordListener(int code, WPARAM wprm, LPARAM
switch(wprm)
{
case WM_KEYDOWN:
// if(_sign)
// {
if(getDataFromSweepGun(code,wprm,lprm))
{
return true;
......@@ -31,6 +40,7 @@ LRESULT CALLBACK KeyboardListener::recordListener(int code, WPARAM wprm, LPARAM
return false;
}
// }
}
return CallNextHookEx(NULL, code, wprm, lprm);
......@@ -58,14 +68,24 @@ void KeyboardListener::setCodeText(std::string code)
void KeyboardListener::clearCode()
{
if(_QCode.size() > 0)
{
if(_QCode.size() == 1)
{
_sign = false;
qDebug() <<"clearCode hooked string length is:"<<_QCode.size() ;
_SimulateKeyboard(_QCode.at(0));
qDebug()<<"send first data wsa hooked ";
_forDataStamp = 0;
_QCode.clear();
}
_forDataStamp = 0;
for(int i = 0;i < _numToDistri.size();i++)
{
_sign = false;
qDebug() <<" clearCode num to distribute data is:"<<_numToDistri.size() ;
_SimulateKeyboard(_numToDistri.at(i));
}
_numToDistri.clear();
}
bool KeyboardListener::getDataFromSweepGun(int code, WPARAM wprm, LPARAM lprm)
......@@ -75,32 +95,42 @@ bool KeyboardListener::getDataFromSweepGun(int code, WPARAM wprm, LPARAM lprm)
if( strct->vkCode >= 48 && strct->vkCode <=57)
{
qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch();
if(_QCode.size() == 0)
{
_timeStamp = timestamp;
const QEvent::Type MyEvent = QEvent::Type(NOCODE_EVENT);
QApplication::sendEvent((QObject*)up,new QEvent(MyEvent) );
qDebug() <<"keybordlistener send event to clear the hooked data";
}
if(_forDataStamp == 0 || timestamp - _forDataStamp < SWEEPTIME) //根据键盘输入时间做判断,输入间隔小于40则认为是扫枪输入的数据
// qDebug() <<"keybordlistener send event to clear the hooked data";
if((_forDataStamp == 0 && _QCode.size() == 0 && _sign ) || timestamp - _forDataStamp < SWEEPTIME) //根据键盘输入时间做判断,输入间隔小于40则认为是扫枪输入的数据
{
_QCode += strct->vkCode;
_forDataStamp = timestamp;
qDebug() << " keyboard num hooked ,num is : "<< strct->vkCode;
std::string tem;
tem += strct->vkCode;
// qDebug() << " keyboard num hooked ,num is : "<<QString::fromStdString(tem);
return true;
}
else
{
qDebug() << " keyboard num not hooked ,num is : "<< strct->vkCode;
return false;
if(_sign)
{
_numToDistri += strct->vkCode;
qDebug()<<" getDataFromSweepGun _sign value" << _sign;
return true;
}
else
{
qDebug()<< "getDataFromSweepGun _sign value" << _sign;
_sign = true;
_forDataStamp = 0;
return false;
}
}
}
else if(strct->vkCode >= VK_RETURN)
else if(strct->vkCode == VK_RETURN)
{
if(dealSweepGunReturn(code,wprm,lprm))
......@@ -115,7 +145,11 @@ bool KeyboardListener::getDataFromSweepGun(int code, WPARAM wprm, LPARAM lprm)
}
}
else return false;
else
{
qDebug()<<"key board data go";
return false;
}
}
bool KeyboardListener::dealSweepGunReturn(int code, WPARAM wprm, LPARAM lprm)
......@@ -123,10 +157,9 @@ bool KeyboardListener::dealSweepGunReturn(int code, WPARAM wprm, LPARAM lprm)
KBDLLHOOKSTRUCT *strct = (KBDLLHOOKSTRUCT *)lprm;
strct->vkCode;
qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch();
qDebug() << " return code size ,_QCode.size()"<< _QCode.size();
qDebug() << " return time period from first num key to return hooked,timestamp-_timeStamp"<< timestamp-_timeStamp;
if(_QCode.size() >= CODELENGTH && timestamp-_timeStamp <TOTALTIME) //拿到的是付款码
{
qDebug()<< "pay code is:"<<QString::fromStdString(_QCode);
up->setText(QString::fromStdString(_QCode));
const QEvent::Type MyEvent = QEvent::Type(CODE_EVENT);
QApplication::sendEvent((QObject*)up,new QEvent(MyEvent) );
......@@ -134,16 +167,26 @@ bool KeyboardListener::dealSweepGunReturn(int code, WPARAM wprm, LPARAM lprm)
_timeStamp = 0;
_forDataStamp = 0;
_QCode.clear();
_SimulateKeyboard(VK_RETURN);
return true;
}
else if(_QCode.size() < CODELENGTH && timestamp-_timeStamp <TOTALTIME)
{
qDebug()<< "prodect code is:"<<QString::fromStdString(_QCode);
for(int i = 0;i < _QCode.size();i++) //商品码不可以被拦截
{
_sign = false;
_SimulateKeyboard(_QCode.at(i));
}
qDebug()<< "prodecut code hooked too";
_QCode.clear();
_timeStamp = 0;
_forDataStamp = 0;
qDebug()<< "prodecut code hooked too";
return true;
_SimulateKeyboard(VK_RETURN);
return false;
}
else
return false;
......
......@@ -11,13 +11,9 @@
const int SWEEPTIME = 40;
const int SWEEPTIME = 30;
const int CODELENGTH = 18 ;
const int TOTALTIME = 200 ;
//SWEEPTIME 单个code 时间戳差值
//CODELENGTH 付款码最小长度
//TOTALTIME 扫完付款码最大时间戳差值
class KeyboardListener:public QObject
......@@ -39,7 +35,9 @@ class KeyboardListener:public QObject
std::string getCodeText();
HHOOK ahook;
BOOL destroy();
private:
static std::string _QCode;
static std::string _numToDistri;
static std::string _retCode;
static qint64 _timeStamp;//记录时间戳,扫码枪数据输入的时间戳会很短
static qint64 _forDataStamp;//前一个数据的时间戳
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment