按键精灵初步,使用winIO实现驱动级模拟按键
winIO是目前非常古老的技术,是用底层驱动来实现程序控制键盘按键,要使用winIO,需要用到两个文件WinIo64.dll,与WinIo64.sys。 也有32为的 WinIO32.dll, WinIO32.sys。基于现在的操作系统,都是用的32位的,且都是win7 以上的了,所以,本文用的是winIO64.dll,WinIO64.sys第一步:命令行运行: cmd-> bcd...
winIO是目前非常古老的技术,是用底层驱动来实现程序控制键盘按键,要使用winIO,需要用到两个文件WinIo64.dll,与WinIo64.sys。 也有32为的 WinIO32.dll, WinIO32.sys。基于现在的操作系统,都是用的32位的,且都是win7 以上的了,所以,本文用的是winIO64.dll,WinIO64.sys
第一步:
命令行运行: cmd-> bcdedit /set testsigning on 把系统用作测试模式
然后第二步: 修改WinIo64.sys的测试签名,我提供的WinIO64.sys,是已经签名了的。 并把 WinIO64.dll,与 winIO64.sys 复制到 C:\Windows\SysWOW64 下。
WinIO所需文件下载地址: http://www.qq249191508.com/article-detials/18
解压密码: www.qq249191508.com
那么现在就可以直接调用WinIO64里面的函数了。
现在提供给大家一个可用的winIO 的C++ 类:
MyWinIO.h
#pragma once
typedef bool (WINAPI *pInitializeWinIo)();
typedef bool (WINAPI *pShutdownWinIo)();
typedef bool (WINAPI *pGetPortVal)(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);
typedef bool (WINAPI *pSetPortVal)(WORD wPortAddr, DWORD dwPortVal, BYTE bSize);
#define KBC_KEY_CMD 0x64
#define KBC_KEY_DATA 0x60
// #define VK_NUMLOCK = 0x90; //数字锁定键
// #define VK_SCROLL = 0x91; //滚动锁定
// #define VK_CAPITAL = 0x14; //大小写锁定
// #define VK_A = 65;
// #define VK_TAB = 9;
// #define VK_Delete = 46;
// #define VK_ENTER = 13;
// #define VK_END = 0x23;
// #define VK_BACK = 0x08;
// #define VK_SHIFT = 0x10;
// #define VK_RETURN = 0x0D;
// #define VK_ESCAPE = 0x1B;
enum MouseEventFlags
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
Wheel = 0x0800,
Absolute = 0x8000
};
class CMyWinIO
{
public:
CMyWinIO();
~CMyWinIO();
void MyKeyDown(byte dwKey);
void KBCWait4IBE();
bool InitWinIO();
void ShutDownIO();
void SetPortVal(WORD wPortAddr, DWORD dwPortVal);
void GetPortVal(WORD wPortAddr, PDWORD dwPortVal);
void MoveMouseToPoint(int xPos, int yPos);
HMODULE m_hWinIo;
private:
pInitializeWinIo io_Init;
pShutdownWinIo io_Shutdown;
pGetPortVal io_GetPortVal;
pSetPortVal io_SetPortVal;
};
MyWinIO.cpp
#include "stdafx.h"
#include "MyWinIO.h"
CMyWinIO::CMyWinIO()
{
m_hWinIo = NULL;
}
CMyWinIO::~CMyWinIO()
{
}
// 注意,这里传入的是字符串的ascii 码
void CMyWinIO::MyKeyDown(byte vKeyCoad)
{
int btScancode = 0;
btScancode = MapVirtualKey((byte)vKeyCoad, 0);
KBCWait4IBE();
io_SetPortVal(KBC_KEY_CMD, 0xD2, 1);// 发送命令
KBCWait4IBE();
io_SetPortVal(KBC_KEY_DATA, (DWORD)btScancode,1);// 写入按下键
KBCWait4IBE();
io_SetPortVal(KBC_KEY_CMD, 0xD2,1);// 发送命令
KBCWait4IBE();
io_SetPortVal(KBC_KEY_DATA, (DWORD)(btScancode | 0x80),1);// 弹出键
}
///等待键盘缓冲区为空
void CMyWinIO::KBCWait4IBE()
{
DWORD dwVal = 0;
do
{
bool flag = io_GetPortVal(0x64, &dwVal, 1);
} while ((dwVal & 0x2) > 0);
}
bool CMyWinIO::InitWinIO()
{
m_hWinIo = LoadLibrary("WinIo32.dll");
if (m_hWinIo == NULL)
{
return false;
}
io_Init = (pInitializeWinIo)GetProcAddress(m_hWinIo, "InitializeWinIo");
if (io_Init != NULL)
{
bool Result = io_Init();
if (!Result)
{
FreeLibrary(m_hWinIo);
}
}
io_Shutdown = (pShutdownWinIo)GetProcAddress(m_hWinIo, "ShutdownWinIo");
io_GetPortVal = (pGetPortVal)GetProcAddress(m_hWinIo, "GetPortVal");
io_SetPortVal = (pSetPortVal)GetProcAddress(m_hWinIo, "SetPortVal");
return false;
}
void CMyWinIO::ShutDownIO()
{
io_Shutdown();
}
void CMyWinIO::SetPortVal(WORD wPortAddr, DWORD dwPortVal)
{
io_SetPortVal(wPortAddr, dwPortVal, 1);
}
void CMyWinIO::GetPortVal(WORD wPortAddr, PDWORD dwPortVal)
{
io_GetPortVal(wPortAddr, dwPortVal, 1);
}
// 鼠标移动
void CMyWinIO::MoveMouseToPoint(int xPos, int yPos)
{
// 移动鼠标
SetCursorPos(xPos, yPos);
// 鼠标左键点击
mouse_event(LeftDown | Absolute, 0, 0, 0, NULL);
// 鼠标左键抬起
mouse_event(LeftUp | Absolute, 0, 0, 0, NULL);
}
现在就可以使用WinIO了.
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)