当前位置:  编程技术>c/c++/嵌入式

简易Dota改键外挂程序制作

    来源: 互联网  发布时间:2014-10-22

    本文导语:  dll部分: 代码如下:// FileName: add.cpp #include /* 定义全局变量 */HWND g_hwnd = NULL;HHOOK g_hKeyboard = NULL; // 设置数据段#pragma data_seg("MySec")static WORD g_keyNum[6]={0};        // 只有初始化过的才能用static int g_signed = 0;#pragma data_seg()  #pragm...



dll部分:

代码如下:

// FileName: add.cpp

#include

/* 定义全局变量 */
HWND g_hwnd = NULL;
HHOOK g_hKeyboard = NULL;

// 设置数据段
#pragma data_seg("MySec")
static WORD g_keyNum[6]={0};        // 只有初始化过的才能用
static int g_signed = 0;
#pragma data_seg() 
#pragma comment( linker,"/section:MySec,RWS" )

LRESULT CALLBACK KeyboardProc(
    int code,       // hook code
    WPARAM wParam,  // virtual-key code
    LPARAM lParam   // keystroke-message information
    )
{
    for(int j=0; j>31) )
        {
            switch(j)
            {
            case 0: keybd_event(VK_NUMPAD1,0,KEYEVENTF_EXTENDEDKEY,0); keybd_event(VK_NUMPAD1,0,KEYEVENTF_KEYUP,0); return 1;
            case 1: keybd_event(VK_NUMPAD2,0,KEYEVENTF_EXTENDEDKEY,0); keybd_event(VK_NUMPAD2,0,KEYEVENTF_KEYUP,0); return 1;
            case 2: keybd_event(VK_NUMPAD4,0,KEYEVENTF_EXTENDEDKEY,0); keybd_event(VK_NUMPAD4,0,KEYEVENTF_KEYUP,0); return 1;
            case 3: keybd_event(VK_NUMPAD5,0,KEYEVENTF_EXTENDEDKEY,0); keybd_event(VK_NUMPAD5,0,KEYEVENTF_KEYUP,0); return 1;
            case 4: keybd_event(VK_NUMPAD7,0,KEYEVENTF_EXTENDEDKEY,0); keybd_event(VK_NUMPAD7,0,KEYEVENTF_KEYUP,0); return 1;
            case 5: keybd_event(VK_NUMPAD8,0,KEYEVENTF_EXTENDEDKEY,0); keybd_event(VK_NUMPAD8,0,KEYEVENTF_KEYUP,0); return 1;
            }
        }
    }
    return CallNextHookEx(g_hKeyboard,code,wParam,lParam);
}
_declspec(dllexport) void SetHook (WORD KeyNum[])
{
    for(int i=0; iLoadIcon(IDR_MAINFRAME);
}

void CDotaDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_EDIT_NUM7, m_num7);
    DDV_MaxChars(pDX, m_num7, 1);
    DDX_Text(pDX, IDC_EDIT_NUM8, m_num8);
    DDV_MaxChars(pDX, m_num8, 1);
    DDX_Text(pDX, IDC_EDIT_NUM4, m_num4);
    DDV_MaxChars(pDX, m_num4, 1);
    DDX_Text(pDX, IDC_EDIT_NUM1, m_num1);
    DDV_MaxChars(pDX, m_num1, 1);
    DDX_Text(pDX, IDC_EDIT_NUM2, m_num2);
    DDV_MaxChars(pDX, m_num2, 1);
    DDX_Text(pDX, IDC_EDIT_NUM5, m_num5);
    DDV_MaxChars(pDX, m_num5, 1);
}

BEGIN_MESSAGE_MAP(CDotaDlg, CDialogEx)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BUTTON_EXIT, &CDotaDlg::OnBnClickedButtonExit)
    ON_EN_SETFOCUS(IDC_EDIT_NUM7, &CDotaDlg::OnEnSetfocusEditNum7)
    ON_WM_DESTROY()
    ON_EN_KILLFOCUS(IDC_EDIT_NUM7, &CDotaDlg::OnEnKillfocusEditNum7)
    ON_EN_SETFOCUS(IDC_EDIT_NUM8, &CDotaDlg::OnEnSetfocusEditNum8)
    ON_EN_KILLFOCUS(IDC_EDIT_NUM8, &CDotaDlg::OnEnKillfocusEditNum8)
    ON_EN_SETFOCUS(IDC_EDIT_NUM4, &CDotaDlg::OnEnSetfocusEditNum4)
    ON_EN_KILLFOCUS(IDC_EDIT_NUM4, &CDotaDlg::OnEnKillfocusEditNum4)
    ON_EN_SETFOCUS(IDC_EDIT_NUM5, &CDotaDlg::OnEnSetfocusEditNum5)
    ON_EN_KILLFOCUS(IDC_EDIT_NUM5, &CDotaDlg::OnEnKillfocusEditNum5)
    ON_EN_SETFOCUS(IDC_EDIT_NUM1, &CDotaDlg::OnEnSetfocusEditNum1)
    ON_EN_KILLFOCUS(IDC_EDIT_NUM1, &CDotaDlg::OnEnKillfocusEditNum1)
    ON_EN_SETFOCUS(IDC_EDIT_NUM2, &CDotaDlg::OnEnSetfocusEditNum2)
    ON_EN_KILLFOCUS(IDC_EDIT_NUM2, &CDotaDlg::OnEnKillfocusEditNum2)
    ON_WM_TIMER()
    ON_BN_CLICKED(IDC_BUTTON_HIDE, &CDotaDlg::OnBnClickedButtonHide)
    ON_MESSAGE(WM_SHOWTASK,OnShowTask)
END_MESSAGE_MAP()

/* 局部钩子处理程序 */
LRESULT CALLBACK KeyboardProc(
    int code,       // hook code
    WPARAM wParam,  // virtual-key code
    LPARAM lParam   // keystroke-message information
    )
{
    /* 按一个键时 */
    if(wParam && !(lParam>>31))
    {
        //CString str;
        //str.Format(L"%d", wParam);
        //AfxMessageBox(str);
        POINT point;
        GetCaretPos(&point);

        for(int i=0; im_num1 = g_szkeyboard[wParam]; g_nkey[0]=wParam; g_pt->UpdateData(FALSE); break;
                        case 1: g_pt->m_num2 = g_szkeyboard[wParam]; g_nkey[1]=wParam; g_pt->UpdateData(FALSE); break;
                        case 2: g_pt->m_num4 = g_szkeyboard[wParam]; g_nkey[2]=wParam; g_pt->UpdateData(FALSE); break;
                        case 3: g_pt->m_num5 = g_szkeyboard[wParam]; g_nkey[3]=wParam; g_pt->UpdateData(FALSE); break;
                        case 4: g_pt->m_num7 = g_szkeyboard[wParam]; g_nkey[4]=wParam; g_pt->UpdateData(FALSE); break;
                        case 5: g_pt->m_num8 = g_szkeyboard[wParam]; g_nkey[5]=wParam; g_pt->UpdateData(FALSE); break;
                    }
                }
                else        // 按下退格键删除以前的改键
                {
                    switch(i)
                    {
                        case 0: g_pt->m_num1 = ""; g_nkey[0]=0; g_pt->UpdateData(FALSE); break;
                        case 1: g_pt->m_num2 = ""; g_nkey[1]=0; g_pt->UpdateData(FALSE); break;
                        case 2: g_pt->m_num4 = ""; g_nkey[2]=0; g_pt->UpdateData(FALSE); break;
                        case 3: g_pt->m_num5 = ""; g_nkey[3]=0; g_pt->UpdateData(FALSE); break;
                        case 4: g_pt->m_num7 = ""; g_nkey[4]=0; g_pt->UpdateData(FALSE); break;
                        case 5: g_pt->m_num8 = ""; g_nkey[5]=0; g_pt->UpdateData(FALSE); break;
                    }
                }
            }
        }
    }
    //return CallNextHookEx(g_hook, code, wParam, lParam);
    return 1;
}

// CDotaDlg 消息处理程序

BOOL CDotaDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    // 将“关于...”菜单项添加到系统菜单中。

    // IDM_ABOUTBOX 必须在系统命令范围内。
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        BOOL bNameValid;
        CString strAboutMenu;
        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
        ASSERT(bNameValid);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
    //  执行此操作
    SetIcon(m_hIcon, TRUE);            // 设置大图标
    SetIcon(m_hIcon, FALSE);        // 设置小图标

    // TODO: 在此添加额外的初始化代码
    SetTimer(1, 1000, NULL);        // 设置一个定时器
    g_pt = this;
    g_szkeyboard['0']="0";g_szkeyboard['1']="1";g_szkeyboard['2']="2";g_szkeyboard['3']="3";g_szkeyboard['4']="4";
    g_szkeyboard['5']="5";g_szkeyboard['6']="6";g_szkeyboard['7']="7";g_szkeyboard['8']="8";g_szkeyboard['9']="9";
    g_szkeyboard['A']="A";g_szkeyboard['B']="B";g_szkeyboard['C']="C";g_szkeyboard['D']="D";g_szkeyboard['E']="E";
    g_szkeyboard['F']="F";g_szkeyboard['G']="G";g_szkeyboard['H']="H";g_szkeyboard['I']="I";g_szkeyboard['J']="J";
    g_szkeyboard['K']="K";g_szkeyboard['L']="L";g_szkeyboard['M']="M";g_szkeyboard['N']="N";g_szkeyboard['O']="O";
    g_szkeyboard['P']="P";g_szkeyboard['Q']="Q";g_szkeyboard['R']="R";g_szkeyboard['S']="S";g_szkeyboard['T']="T";
    g_szkeyboard['U']="U";g_szkeyboard['V']="V";g_szkeyboard['W']="W";g_szkeyboard['X']="X";g_szkeyboard['Y']="Y";
    g_szkeyboard['Z']="Z";
    g_szkeyboard[144]="NUM LOCK";
    g_szkeyboard[96]="NUM 0";g_szkeyboard[97]="NUM 1";g_szkeyboard[98]="NUM 2";g_szkeyboard[99]="NUM 3";g_szkeyboard[100]="NUM 4";
    g_szkeyboard[101]="NUM 5";g_szkeyboard[102]="NUM 6";g_szkeyboard[103]="NUM 7";g_szkeyboard[104]="NUM 8";g_szkeyboard[105]="NUM 9";
    g_szkeyboard[106]="NUM *";g_szkeyboard[107]="NUM +";g_szkeyboard[109]="NUM -";g_szkeyboard[110]="NUM DEL";g_szkeyboard[111]="NUM /";
    g_szkeyboard[VK_F1]="F1";g_szkeyboard[VK_F2]="F2";g_szkeyboard[VK_F3]="F3";g_szkeyboard[VK_F4]="F4";g_szkeyboard[VK_F5]="F5";
    g_szkeyboard[VK_F6]="F6";g_szkeyboard[VK_F7]="F7";g_szkeyboard[VK_F8]="F8";g_szkeyboard[VK_F9]="F9";g_szkeyboard[VK_F10]="F10";
    g_szkeyboard[VK_F11]="F11";g_szkeyboard[VK_F12]="F12";
    g_szkeyboard[VK_ESCAPE]="ESC";g_szkeyboard[VK_TAB]="TAB";g_szkeyboard[VK_CAPITAL]="Caps Lock";g_szkeyboard[192]="`";
    g_szkeyboard[VK_SPACE]="Space";

    /* 安装局部钩子 */
    g_hook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, NULL, GetCurrentThreadId());

    ReadKeyNum();

    return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}

void CDotaDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialogEx::OnSysCommand(nID, lParam);
    }
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CDotaDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // 用于绘制的设备上下文

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0);

        // 使图标在工作区矩形中居中
        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;

        // 绘制图标
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CDotaDlg::OnQueryDragIcon()
{
    return static_cast(m_hIcon);
}

BOOL CDotaDlg::PreTranslateMessage (MSG * pMsg)
{

    switch(pMsg->wParam)
    {
        case VK_ESCAPE:            // 屏蔽ESC键
            return TRUE;
    }
    return CDialog::PreTranslateMessage(pMsg);
}

 

void CDotaDlg::OnBnClickedButtonExit()
{
    //OnNotifyMsg();
    SendMessage(WM_CLOSE);
}

void CDotaDlg::OnDestroy()
{
    CDialogEx::OnDestroy();

    g_pt = NULL;
    KillTimer(1);
    /* 卸载钩子 */
    UnhookWindowsHookEx(g_hook);
}

void CDotaDlg::OnEnSetfocusEditNum7()
{
    g_signNum[4] = true;
}


void CDotaDlg::OnEnKillfocusEditNum7()
{
    g_signNum[4] = false;
}


void CDotaDlg::OnEnSetfocusEditNum8()
{
    g_signNum[5] = true;
}


void CDotaDlg::OnEnKillfocusEditNum8()
{
    g_signNum[5] = false;
}


void CDotaDlg::OnEnSetfocusEditNum4()
{
    g_signNum[2] = true;
}


void CDotaDlg::OnEnKillfocusEditNum4()
{
    g_signNum[2] = false;
}


void CDotaDlg::OnEnSetfocusEditNum5()
{
    g_signNum[3] = true;
}


void CDotaDlg::OnEnKillfocusEditNum5()
{
    g_signNum[3] = false;
}


void CDotaDlg::OnEnSetfocusEditNum1()
{
    g_signNum[0] = true;
}


void CDotaDlg::OnEnKillfocusEditNum1()
{
    g_signNum[0] = false;
}


void CDotaDlg::OnEnSetfocusEditNum2()
{
    g_signNum[1] = true;
}


void CDotaDlg::OnEnKillfocusEditNum2()
{
    g_signNum[1] = false;
}

_declspec(dllimport) void SetHook (WORD KeyNum[]);
_declspec(dllimport) void DelHook ();

void CDotaDlg::OnTimer(UINT_PTR nIDEvent)
{
    static int sign = 1;
    HWND hwnd =    NULL;
    hwnd = ::FindWindow(L"Warcraft III",0);            // 获得顶层窗口句柄
    if(hwnd == ::GetForegroundWindow())                // 得到前台窗口句柄
    {
        if(sign)
        {
        //MessageBox(L"找到目标进程了");
        //DelHook(); 
            SetHook(g_nkey);    // 安装钩子。
            sign = 0;
        }
    }
    else
    {
        DelHook();
        sign = 1;
    }

    CDialogEx::OnTimer(nIDEvent);
}

_declspec(dllimport) void SetHook (WORD KeyNum[]);
void CDotaDlg::OnBnClickedButtonHide()
{
    //SetHook(g_nkey);
    CStdioFile file;
    CString str;
    CFileException mExcept;
    file.Open(L"Key.ini", CFile::modeCreate|CFile::modeReadWrite, &mExcept);
    file.SeekToEnd();
    str.Format(L"@%d-->1@n@%d-->2@n@%d-->4@n@%d-->5@n@%d-->7@n@%d-->8@n",
        g_nkey[0], g_nkey[1], g_nkey[2], g_nkey[3], g_nkey[4], g_nkey[5]);
    file.WriteString(str);
    file.Close();

    NOTIFYICONDATA nid;   

    nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);  

    nid.hWnd=this->m_hWnd;   

    nid.uID=IDR_MAINFRAME;   

    nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP ;   

    nid.uCallbackMessage=WM_SHOWTASK;//自定义的消息名称   

    nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));

    wcscpy(nid.szTip, L"冬雪简易改键");    //信息提示条  

    Shell_NotifyIcon(NIM_ADD,&nid);    //在托盘区添加图标   

    ShowWindow(SW_HIDE);    //隐藏主窗口
}

void CDotaDlg::ReadKeyNum(void)
{
    CStdioFile file;
    if(file.Open(L"Key.ini", CFile::modeRead))
    {
        CString buffer;
        char buf[4];
        int i;
        int j = 0;
        memset(buf,0,4);
        while(file.ReadString(buffer))
        {
            i = 0;
            for(i=0; im_hWnd;   

    nid.uID=IDR_MAINFRAME;   

    nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP ;   

    nid.uCallbackMessage=WM_SHOWTASK;//自定义的消息名称   

    nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));  

    wcscpy(nid.szTip,L"冬雪简易改键");    //信息提示条  

    Shell_NotifyIcon(NIM_ADD,&nid);    //在托盘区添加图标   

    ShowWindow(SW_HIDE);    //隐藏主窗口

}

LRESULT CDotaDlg::OnShowTask(WPARAM wParam,LPARAM lParam)  
{    
    if(wParam!=IDR_MAINFRAME)       
        return 1;     
    switch(lParam)    
    {           
    case WM_RBUTTONUP://右键起来时弹出快捷菜单,这里只有一个“关闭”      
        {        
            LPPOINT lpoint= new tagPOINT;        
            ::GetCursorPos(lpoint);//得到鼠标位置         
            CMenu menu;            
            menu.CreatePopupMenu();//声明一个弹出式菜单         
            //增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口(已            
            //隐藏),将程序结束。           
            menu.AppendMenu(MF_STRING,WM_DESTROY,L"关闭"); 
            //          menu.AppendMenu(MF_STRING,WM_DESTROY,"设置..."); 
            //确定弹出式菜单的位置          
            menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,this);       
            //资源回收           
            HMENU hmenu=menu.Detach();             
            menu.DestroyMenu();            
            delete lpoint;       
        }            
        break;         
    case WM_LBUTTONDBLCLK://双击左键的处理       
        {          

            ShowWindow(SW_SHOWNORMAL);//简单的显示主窗口完事儿   SW_SHOW则错误 

            //  this->SetForegroundWindow(); // 置顶显示         
            //~DeleteTray();       
        }            
        break;         
    default:            
        break;     
    }     
    return 0; 
}



还可参考 dota改键精灵 v4.8.7 绿色版 附使用教程及注意事项 和 dota改键精灵(dota改建器) v4.88 免费 绿色版

    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 上网代理goagent 3.1.18 正式版下载及简易安装部署教程
  • 简易定时闹铃工具 Alarm Clock
  • 简易个人博客 LnBlog
  • 简易内容管理系统 CMSimple
  • 简易数据库客户端 ajfdbviewer
  • Java简易MVC框架 etmvc
  • 简易MVC框架 Lanp
  • 简易相册系统 MeiuPic
  • 简易中文分词系统 SCWS
  • 建立简易linux系统
  • 简易的ioc容器 Facility Container
  • 简易Java数据持久层框架 Siena
  • 简易的Java ORM框架 Kauklahti
  • 简易HTTP爬虫 HttpBot
  • 请问各位大虾,在linux下如何简易阅读文本文件。
  • 简易个人笔记记录式系统 fwrite
  • PHP中替换键名的简易方法示例详解
  • 请问是谁想要参考数据输入输出流的流量监控?这儿有一个简易的例子供参考
  • 基于jquery的simpleValidate简易验证插件
  • python搭建简易服务器分析与实现
  • 探讨Object转为String的几种简易形式详解


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3