Click here to Skip to main content
Licence CPOL
First Posted 20 Feb 2008
Views 28,875
Bookmarked 16 times

How to use your extra mouse buttons in games or apps

By | 20 Feb 2008 | Article
So you have your brand new El-Cheapo mouse with a zillion of additional mouse buttons yet you can't use them in games. Lets see one solution to this problem

Introduction

As a fan of World Of Warcraft game I recently went shoping for mouse with extra buttons. The idea was that binding extra spells in game to those buttons will radically improve my reaction times. Such was the theory. But as I unpacked my brand new mouse and started so called mouse configuration panel i found out that only 2 of additional 6 extra buttons were programmable . And even those 2 had just limited assignable functionality such as "start email client" etc. Errrr

Background

But I am curious person and i started to study this driver software. Soon i discovered that majority of the cheap mouses use the same drivers. So if you see KMProcess running you are a lucky guy. By launching usefull microsoft Spy++ I also soon found out that for each extra mouse button pressed this universal mouse driver generates custom WM_USER based message. So the idea was to capture those messages and react by emulating driver level keyboard imput so those buttons will be seen as regullar bindable keyboard buttons to games.

If you don't have KMProcess running don't worry. There is second and what is more important vendor / driver independent method. I will add code sample for this method soon so stay in touch

Using the code

The code for KMProcess method itself is very simple. It captures the internal custom mouse button mesages and translates it to F1-F6 key presses. But nothing holds you from lets-say executing whatever different action you wish. You can even simulate mouse movements or multiple key sequences to games by using function SendInput() instead of used keybd_event()
#include <windows.h>
#include <stdio.h>

HHOOK  hook       =  0;
char   target[32] = {0};
int    last       =  0; 

void btn(int i,int up) { 
    if(3*up+i != last)  keybd_event(VK_F1+i,MapVirtualKey(VK_F1+i,0),up,0);
    last = 3*up+i;
}

LRESULT  CALLBACK proc(int disabled,WPARAM wp,LPARAM lp) {
    int *m = (int *)lp;
    if (!disabled) {
        if( m[1] == 0x0465 && m[2] == 0x0000 && m[3] == 2 )   btn(0,0); 
        if( m[1] == 0x0464 && m[2] == 0x0000 && m[3] == 2 )   btn(0,2); 
        if( m[1] == 0x0465 && m[2] == 0x0000 && m[3] == 4 )   btn(1,0); 
        if( m[1] == 0x0464 && m[2] == 0x0000 && m[3] == 4 )   btn(1,2); 
        if( m[1] == 0x1f58 && m[2] == 0x1b70 && m[3] == 0 )   btn(2,0); 
        if( m[1] == 0x1f58 && m[2] == 0x1b70 && m[3] == 1 )   btn(2,2); 
        if( m[1] == 0x1f58 && m[2] == 0x1b71 && m[3] == 0 )   btn(3,0); 
        if( m[1] == 0x1f58 && m[2] == 0x1b71 && m[3] == 1 )   btn(3,2); 
        if( m[1] == 0x1f58 && m[2] == 0x1b72 && m[3] == 0 ) { btn(4,0); Sleep(10); btn(4,2); } 
        if( m[1] == 0x1f58 && m[2] == 0x1b73 && m[3] == 0 ) { btn(5,0); Sleep(10); btn(5,2); } 
    }
    return CallNextHookEx(hook,disabled,wp,lp);
}

extern "C" __declspec(dllexport) void inst(HWND, HINSTANCE, char* cmd){
    if(!cmd||hook) return;  strncpy(target,cmd,sizeof(target));
    hook   = SetWindowsHookEx(WH_GETMESSAGE,proc,GetModuleHandle("hook"),0);
    MSG msg; while(GetMessage(&msg,0,0,0)) { TranslateMessage( &msg ); DispatchMessage(  &msg ); Sleep(10); }
}

long __stdcall DllMain( HINSTANCE dll,DWORD  reason){ 
    return strstr(GetCommandLine(),target) ? 1 : 0;
}

Points of Interest

Just build dll in whatever developmnet environment you have copy it do windows dir and install it from Start->Run.. Dialog

rundll32 hook,inst KMProcess

or from command line

start rundll32 hook,inst KMProcess

where hook is the name of dll and KMProcess is the name of the mouse driver process

Also if you are a not programmer don't worry. Just extract included zip file and run bat file.

History

As soon as I will have time I will add second method plus version with some nice Gui allowing to record and play mouse and keyboard macros on any mouse button press.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ladislav Nevery

Software Developer (Senior)

Slovakia Slovakia

Member

Past Projects:
[Siemens.sk]Mobile network software: HLR-Inovation for telering.at (Corba)
Medical software: CorRea module for CT scanner
[cauldron.sk]Computer Games:XboxLive/net code for Conan, Knights of the temple II, GeneTroopers, CivilWar, Soldier of fortune II
[www.elveon.com]Computer Games:XboxLive/net code for Elveon game based on Unreal Engine 3

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionIs the file removed? PinmemberShiine6:46 26 Oct '09  
Questionhow to unistall ? Pinmembergrizleygrizley3:13 4 Sep '08  
QuestionCould this be used for joystick buttons also? PinmemberdavidMelloWorkAddress1:57 26 Feb '08  
Could this be used for joystick buttons. I am thinking of taking apart a usb joystick and using the buttons to setup a quick access panel. That way I can program additional features into the quick action panel. Can World of warcraft accept joystick inputs? Or would it have to be tricked like the method you mention for getting additional mouse messaages.
 
Thanks In Advance.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 20 Feb 2008
Article Copyright 2008 by Ladislav Nevery
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid