有一个游戏,用键盘操作,但因为键位不能设置。我想做一个软件能手动设置好键位适合不同的玩家习惯,我应该使用什么原理来做。用VB,VC都可以的.

解决方案 »

  1.   

    对于非DirectX的游戏
    挂键盘钩子
    在钩子中修改按键注意
    跨进成键盘钩子需要写dll
    可是VB不能编译普通dll
    底层键盘钩子虽然不需要dll,但只支持NT平台
      

  2.   

    SetWindowsHookEx Function--------------------------------------------------------------------------------The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread. SyntaxHHOOK SetWindowsHookEx(          int idHook,
        HOOKPROC lpfn,
        HINSTANCE hMod,
        DWORD dwThreadId
    );
    ParametersidHook
    [in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values. 
    WH_CALLWNDPROC
    Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more information, see the CallWndProc hook procedure.
    WH_CALLWNDPROCRET
    Installs a hook procedure that monitors messages after they have been processed by the destination window procedure. For more information, see the CallWndRetProc hook procedure.
    WH_CBT
    Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application. For more information, see the CBTProc hook procedure.
    WH_DEBUG
    Installs a hook procedure useful for debugging other hook procedures. For more information, see the DebugProc hook procedure.
    WH_FOREGROUNDIDLE
    Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the ForegroundIdleProc hook procedure. 
    WH_GETMESSAGE
    Installs a hook procedure that monitors messages posted to a message queue. For more information, see the GetMsgProc hook procedure.
    WH_JOURNALPLAYBACK
    Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. For more information, see the JournalPlaybackProc hook procedure.
    WH_JOURNALRECORD
    Installs a hook procedure that records input messages posted to the system message queue. This hook is useful for recording macros. For more information, see the JournalRecordProc hook procedure.
    WH_KEYBOARD
    Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
    WH_KEYBOARD_LL
    Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.
    WH_MOUSE
    Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
    WH_MOUSE_LL
    Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.
    WH_MSGFILTER
    Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. For more information, see the MessageProc hook procedure.
    WH_SHELL
    Installs a hook procedure that receives notifications useful to shell applications. For more information, see the ShellProc hook procedure.
    WH_SYSMSGFILTER
    Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the same desktop as the calling thread. For more information, see the SysMsgProc hook procedure.
    lpfn
    [in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process. 
    hMod
    [in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process. 
    dwThreadId
    [in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread. 
    Return ValueIf the function succeeds, the return value is the handle to the hook procedure. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
    ResAn error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process. Calling the CallNextHookEx function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications. Before terminating, an application must call the UnhookWindowsHookEx function to free system resources associated with the hook. The scope of a hook depends on the hook type. Some hooks can be set only with global scope; others can also be set for only a specific thread, as shown in the following table. Hook Scope 
    WH_CALLWNDPROC Thread or global 
    WH_CALLWNDPROCRET Thread or global 
    WH_CBT Thread or global 
    WH_DEBUG Thread or global 
    WH_FOREGROUNDIDLE Thread or global 
    WH_GETMESSAGE Thread or global 
    WH_JOURNALPLAYBACK Global only 
    WH_JOURNALRECORD Global only 
    WH_KEYBOARD Thread or global 
    WH_KEYBOARD_LL Global only 
    WH_MOUSE Thread or global 
    WH_MOUSE_LL Global only 
    WH_MSGFILTER Thread or global 
    WH_SHELL Thread or global 
    WH_SYSMSGFILTER Global only 
    For a specified hook type, thread hooks are called first, then global hooks. The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure. Windows 95/98/Me: SetWindowsHookEx is supported by the Microsoft® Layer for Unicode (MSLU). However, it does not make conversions. To see Unicode messages, notifications, and so forth, you must subclass the window. To use this version of the application programming interface (API), you must add certain files to your application, as outlined in Installing and Releasing Hook Procedures.ExampleFor an example, see Installing and Releasing Hook Procedures.Function InformationHeader Declared in Winuser.h, include Windows.h 
    Import library User32.lib 
    Minimum operating systems Windows 95, Windows NT 3.1 
    Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP 
      

  3.   

    http://www.lihuasoft.net/book/show.php?id=970勾子编程指南  
     发表日期:2005-12-10 文件大小:103KB 下载次数:135   
     
    版权所有:
    软件版本:文本+代码
    文件大小:103KB
    操作系统:win9x/NT/2000/XP
    下载说明: 关于钩子HOOK函数的详细说明