0

I'm using the following winapi-code to change the right-button clicks with left-button clicks.

LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{

    if (wParam == WM_RBUTTONDOWN)
    {
        return CallNextHookEx(NULL, nCode, WM_LBUTTONDOWN, lParam);
    }
    else if (wParam == WM_RBUTTONUP)
    {
        return CallNextHookEx(NULL, nCode, WM_LBUTTONUP, lParam);
    }
    else if (wParam == WM_RBUTTONDBLCLK)
    {
        return CallNextHookEx(NULL, nCode, WM_LBUTTONDBLCLK, lParam);
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
 }

The hook works very good, but it seems that this technique is read-only (I read this in some other stackoverflow question). This is what I want to do:

Left click -> Press left button.
Right click -> Press left button.

Any ideas how can I achieve this?

Thanks in advance.

cdonts
  • 9,304
  • 4
  • 46
  • 72
  • Thanks for your comment, but that will swap the buttons, I want to just change the right with the left. – cdonts Jan 31 '14 at 23:38
  • Maybe because of my poor English I'm not understanding. This is what I want to do: `Left click -> Press left button. Right click -> Press left button.`. Using `SystemParametersInfo` will do `Left click -> Press right button. Right click -> Press left button.` right? Or I'm wrong? – cdonts Jan 31 '14 at 23:51
  • Sorry for the confusion :-). However, I never used the *swap* word, I just said *change the right-button clicks with left-button clicks*. Thanks again. – cdonts Jan 31 '14 at 23:58
  • No problem. Also it's difficult to me sometimes to explain my problems in English. Btw, any ideas? – cdonts Feb 01 '14 at 00:01
  • In English, "change x with y" means "swap x with y". You meant to write "change x to y". Do you want to do this globally or just within your program? – Raymond Chen Feb 02 '14 at 07:16
  • @RaymondChen Thanks for your comment, I didn't know that about the language! Mmm I think for me it's the same, it will be better if I do it within my program but it's the same. Any ideas? Thanks again. – cdonts Feb 06 '14 at 18:30
  • If it's just your program, then you can do `if (message == WM_RBUTTONDOWN) message = WM_LBUTTONDOWN` for example. – Raymond Chen Feb 06 '14 at 20:16
  • Thanks for your answer. That's what I'm doing (see the code above), but it seems that Windows Hooks are read-only. Any other idea? – cdonts Feb 06 '14 at 21:35
  • Swap them in your window procedure, not in a hook. – Raymond Chen Feb 07 '14 at 00:22
  • That should work, but I'm using a DLL that is loaded in a 3rd process. Will that work? – cdonts Feb 07 '14 at 02:29
  • It will work for your DLL's windows. – Raymond Chen Feb 07 '14 at 03:52
  • My DLL doesn't launch any window. So I think that's not a solution. But really thank you very very much for your help. Any other idea? – cdonts Feb 08 '14 at 01:51
  • You need the cooperation of the windows to get this to work. For example, if they call `GetKeyState(VK_LBUTTON)` they need to know to check `GetKeyState(VK_RBUTTON)` too. – Raymond Chen Feb 08 '14 at 06:53
  • Sorry I don't understand that. How can `GetKeyState` help me here? – cdonts Feb 08 '14 at 22:45
  • I'm not saying it helps you. I'm saying that it hurts you. – Raymond Chen Feb 09 '14 at 15:23

1 Answers1

0

You can use SwapMouseButton function easily to swap mouse buttons.

Mustafa Chelik
  • 2,113
  • 2
  • 17
  • 29
  • Thanks for your answer but I don't want to *swap* the buttons, I want to change the right button with the left button. – cdonts Feb 01 '14 at 21:49
  • 1
    I don't see any difference. What do you mean exactly by changing the right/left key? – Mustafa Chelik Feb 01 '14 at 21:52
  • See the comments to the original question. I asked @cdonts to edit the question to make it clear, but the request was rejected. – Ken White Feb 01 '14 at 22:02
  • 1
    Oh, I see. Well, you can use SwapMouseButton to swap them when user uses your application and swap back when leaving your application. – Mustafa Chelik Feb 01 '14 at 22:07
  • It wasn't rejected @KenWhite, it's just that I don't know what to edit! How can I make the question clearer? Mustafa, I'll check out that. Thanks! – cdonts Feb 01 '14 at 22:18
  • @cdonts: The exact information that I asked you to add, and that I just referred this poster to: [the comment where you made it clear what you were asking](http://stackoverflow.com/questions/21491859/how-to-change-the-right-with-the-left-button/21504048?noredirect=1#comment32442613_21491859). – Ken White Feb 01 '14 at 22:23