How do I swap primary and secondary mouse buttons from the command line or by using a hotkey without...












0















My eight-year-old son is left-handed and I am right-handed. I wish to be able to quickly and easily switch primary and secondary mouse buttons from the command line. We use Windows 10. I found this, which provides c and C#* solutions. I found this which provides a solution which does require rebooting, and also provides a link to the Stack Overflow answer. However, it seems to me that this should be possible to do without resorting to a compiled language. I would be happy with a solution using PowerShell, Python, Perl, a nircmd utility, etc., but I'd rather not resort to a compiled language.



Thank you for your help.




  • FYI if you're interested: the language name apparently uses the "#" (U+0023 # NUMBER SIGN) character, not the "♯" (U+266F ♯ MUSIC SHARP SIGN) character, even though its name is pronounced C Sharp. cf. https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Name.


Edit: Changed question to add "...or by using a hotkey...", since I ultimately wanted to do this with an Autohotkey hotkey; it turns out that Autohotkey can do the swap itself. I was assuming that the answer would be e.g. a Powershell script, which I would invoke by using an Autohotkey hotkey. See the accepted answer.










share|improve this question

























  • Would you be ok with an AutoHotkey script. Would be pretty easy to make a toggle function.

    – Confuzing
    Aug 24 '17 at 19:59











  • Although this isn't guaranteed to work with all programs.

    – Confuzing
    Aug 24 '17 at 20:03











  • I have never done this, and I don't know powershell well, but look at DLLImport and see, for example, ( stackoverflow.com/questions/24391367 ). Put that together with the info from your C# example. I have seen examples of VBS windows API hacks where you automate excel by attaching a temp function, but that is hairy IMO

    – Yorik
    Aug 24 '17 at 21:24













  • Confuzing, Autohotkey would be fine. I use it for a lot (for example, while composing this question I modified my normal script so that I can type ";sharp" and it will insert a sharp symbol). I did not know that Autohotkey could do this. I can probably figure it out myself at this point. Thank you very much

    – ludinom
    Aug 24 '17 at 21:59













  • Yorick, thank you very much. I will probably go the AHK route.

    – ludinom
    Aug 24 '17 at 22:01
















0















My eight-year-old son is left-handed and I am right-handed. I wish to be able to quickly and easily switch primary and secondary mouse buttons from the command line. We use Windows 10. I found this, which provides c and C#* solutions. I found this which provides a solution which does require rebooting, and also provides a link to the Stack Overflow answer. However, it seems to me that this should be possible to do without resorting to a compiled language. I would be happy with a solution using PowerShell, Python, Perl, a nircmd utility, etc., but I'd rather not resort to a compiled language.



Thank you for your help.




  • FYI if you're interested: the language name apparently uses the "#" (U+0023 # NUMBER SIGN) character, not the "♯" (U+266F ♯ MUSIC SHARP SIGN) character, even though its name is pronounced C Sharp. cf. https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Name.


Edit: Changed question to add "...or by using a hotkey...", since I ultimately wanted to do this with an Autohotkey hotkey; it turns out that Autohotkey can do the swap itself. I was assuming that the answer would be e.g. a Powershell script, which I would invoke by using an Autohotkey hotkey. See the accepted answer.










share|improve this question

























  • Would you be ok with an AutoHotkey script. Would be pretty easy to make a toggle function.

    – Confuzing
    Aug 24 '17 at 19:59











  • Although this isn't guaranteed to work with all programs.

    – Confuzing
    Aug 24 '17 at 20:03











  • I have never done this, and I don't know powershell well, but look at DLLImport and see, for example, ( stackoverflow.com/questions/24391367 ). Put that together with the info from your C# example. I have seen examples of VBS windows API hacks where you automate excel by attaching a temp function, but that is hairy IMO

    – Yorik
    Aug 24 '17 at 21:24













  • Confuzing, Autohotkey would be fine. I use it for a lot (for example, while composing this question I modified my normal script so that I can type ";sharp" and it will insert a sharp symbol). I did not know that Autohotkey could do this. I can probably figure it out myself at this point. Thank you very much

    – ludinom
    Aug 24 '17 at 21:59













  • Yorick, thank you very much. I will probably go the AHK route.

    – ludinom
    Aug 24 '17 at 22:01














0












0








0


1






My eight-year-old son is left-handed and I am right-handed. I wish to be able to quickly and easily switch primary and secondary mouse buttons from the command line. We use Windows 10. I found this, which provides c and C#* solutions. I found this which provides a solution which does require rebooting, and also provides a link to the Stack Overflow answer. However, it seems to me that this should be possible to do without resorting to a compiled language. I would be happy with a solution using PowerShell, Python, Perl, a nircmd utility, etc., but I'd rather not resort to a compiled language.



Thank you for your help.




  • FYI if you're interested: the language name apparently uses the "#" (U+0023 # NUMBER SIGN) character, not the "♯" (U+266F ♯ MUSIC SHARP SIGN) character, even though its name is pronounced C Sharp. cf. https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Name.


Edit: Changed question to add "...or by using a hotkey...", since I ultimately wanted to do this with an Autohotkey hotkey; it turns out that Autohotkey can do the swap itself. I was assuming that the answer would be e.g. a Powershell script, which I would invoke by using an Autohotkey hotkey. See the accepted answer.










share|improve this question
















My eight-year-old son is left-handed and I am right-handed. I wish to be able to quickly and easily switch primary and secondary mouse buttons from the command line. We use Windows 10. I found this, which provides c and C#* solutions. I found this which provides a solution which does require rebooting, and also provides a link to the Stack Overflow answer. However, it seems to me that this should be possible to do without resorting to a compiled language. I would be happy with a solution using PowerShell, Python, Perl, a nircmd utility, etc., but I'd rather not resort to a compiled language.



Thank you for your help.




  • FYI if you're interested: the language name apparently uses the "#" (U+0023 # NUMBER SIGN) character, not the "♯" (U+266F ♯ MUSIC SHARP SIGN) character, even though its name is pronounced C Sharp. cf. https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Name.


Edit: Changed question to add "...or by using a hotkey...", since I ultimately wanted to do this with an Autohotkey hotkey; it turns out that Autohotkey can do the swap itself. I was assuming that the answer would be e.g. a Powershell script, which I would invoke by using an Autohotkey hotkey. See the accepted answer.







windows mouse autohotkey accessibility






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 25 '17 at 23:00







ludinom

















asked Aug 24 '17 at 18:20









ludinomludinom

209




209













  • Would you be ok with an AutoHotkey script. Would be pretty easy to make a toggle function.

    – Confuzing
    Aug 24 '17 at 19:59











  • Although this isn't guaranteed to work with all programs.

    – Confuzing
    Aug 24 '17 at 20:03











  • I have never done this, and I don't know powershell well, but look at DLLImport and see, for example, ( stackoverflow.com/questions/24391367 ). Put that together with the info from your C# example. I have seen examples of VBS windows API hacks where you automate excel by attaching a temp function, but that is hairy IMO

    – Yorik
    Aug 24 '17 at 21:24













  • Confuzing, Autohotkey would be fine. I use it for a lot (for example, while composing this question I modified my normal script so that I can type ";sharp" and it will insert a sharp symbol). I did not know that Autohotkey could do this. I can probably figure it out myself at this point. Thank you very much

    – ludinom
    Aug 24 '17 at 21:59













  • Yorick, thank you very much. I will probably go the AHK route.

    – ludinom
    Aug 24 '17 at 22:01



















  • Would you be ok with an AutoHotkey script. Would be pretty easy to make a toggle function.

    – Confuzing
    Aug 24 '17 at 19:59











  • Although this isn't guaranteed to work with all programs.

    – Confuzing
    Aug 24 '17 at 20:03











  • I have never done this, and I don't know powershell well, but look at DLLImport and see, for example, ( stackoverflow.com/questions/24391367 ). Put that together with the info from your C# example. I have seen examples of VBS windows API hacks where you automate excel by attaching a temp function, but that is hairy IMO

    – Yorik
    Aug 24 '17 at 21:24













  • Confuzing, Autohotkey would be fine. I use it for a lot (for example, while composing this question I modified my normal script so that I can type ";sharp" and it will insert a sharp symbol). I did not know that Autohotkey could do this. I can probably figure it out myself at this point. Thank you very much

    – ludinom
    Aug 24 '17 at 21:59













  • Yorick, thank you very much. I will probably go the AHK route.

    – ludinom
    Aug 24 '17 at 22:01

















Would you be ok with an AutoHotkey script. Would be pretty easy to make a toggle function.

– Confuzing
Aug 24 '17 at 19:59





Would you be ok with an AutoHotkey script. Would be pretty easy to make a toggle function.

– Confuzing
Aug 24 '17 at 19:59













Although this isn't guaranteed to work with all programs.

– Confuzing
Aug 24 '17 at 20:03





Although this isn't guaranteed to work with all programs.

– Confuzing
Aug 24 '17 at 20:03













I have never done this, and I don't know powershell well, but look at DLLImport and see, for example, ( stackoverflow.com/questions/24391367 ). Put that together with the info from your C# example. I have seen examples of VBS windows API hacks where you automate excel by attaching a temp function, but that is hairy IMO

– Yorik
Aug 24 '17 at 21:24







I have never done this, and I don't know powershell well, but look at DLLImport and see, for example, ( stackoverflow.com/questions/24391367 ). Put that together with the info from your C# example. I have seen examples of VBS windows API hacks where you automate excel by attaching a temp function, but that is hairy IMO

– Yorik
Aug 24 '17 at 21:24















Confuzing, Autohotkey would be fine. I use it for a lot (for example, while composing this question I modified my normal script so that I can type ";sharp" and it will insert a sharp symbol). I did not know that Autohotkey could do this. I can probably figure it out myself at this point. Thank you very much

– ludinom
Aug 24 '17 at 21:59







Confuzing, Autohotkey would be fine. I use it for a lot (for example, while composing this question I modified my normal script so that I can type ";sharp" and it will insert a sharp symbol). I did not know that Autohotkey could do this. I can probably figure it out myself at this point. Thank you very much

– ludinom
Aug 24 '17 at 21:59















Yorick, thank you very much. I will probably go the AHK route.

– ludinom
Aug 24 '17 at 22:01





Yorick, thank you very much. I will probably go the AHK route.

– ludinom
Aug 24 '17 at 22:01










2 Answers
2






active

oldest

votes


















3














Here is what I came up with for AHK. Just toggles rebinding the mouse buttons with ctrl+alt+m



swap:
swap=false

^!m::
swap := !swap

#if !swap
RButton::LButton
LButton::RButton





share|improve this answer
























  • Thanks a lot! I hadn't had a chance to get back to this and write it myself, but you saved me the trouble. Sorry to put you to the trouble, I could have figured it out once you pointed me in the direction of AHK. I dropped this into my standard AHK script which runs at startup, used a different key (I normally use ^#! for my AHK hotkeys, but ^#!m is already used by Remember the Milk, so I used ^#!s, for swap) and it works great. I'm sorry I can't upvote; or rather, I upvoted but it doesn't count, because I have <15 reputation, so my opinion is recorded but not displayed.

    – ludinom
    Aug 25 '17 at 20:57













  • @Confuzing, very nice solution. Only one question, it's always started as left handed, do you know how to make it start as right handed by default. I was trying to change swap=false, but that doesn't help. Thanks!

    – electroid
    Oct 7 '18 at 15:14






  • 1





    @electroid Changing swap to true should have worked. But you could change the '#if !swap' to '#if swap', or probably even easier to just reverse them in Windows mouse settings.

    – Confuzing
    Oct 7 '18 at 15:58











  • @Confuzing, your solution change the #if !swap to #if swap working just fine! Thanks!

    – electroid
    Oct 7 '18 at 17:54



















1














This is the answer, which was posted on https://superuser.com/a/1357020/790554.



This is the Autohotkey version (modified/based on https://github.com/jNizM/AHK_DllCall_WinAPI/blob/master/src/Mouse%20Input%20Functions/SwapMouseButton.ahk).



; autohotkey code - mapped to F12
F12::
buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 1)
if buttonState <> 0
{
buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 0)
}


This works fine with all Windows (including Windows 10). I usually map it to a hotkey such as "F12" key on my keyboard (using Autohotkey), and I can toggle between left and right mouse button instantly with press of a key.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1244084%2fhow-do-i-swap-primary-and-secondary-mouse-buttons-from-the-command-line-or-by-us%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Here is what I came up with for AHK. Just toggles rebinding the mouse buttons with ctrl+alt+m



    swap:
    swap=false

    ^!m::
    swap := !swap

    #if !swap
    RButton::LButton
    LButton::RButton





    share|improve this answer
























    • Thanks a lot! I hadn't had a chance to get back to this and write it myself, but you saved me the trouble. Sorry to put you to the trouble, I could have figured it out once you pointed me in the direction of AHK. I dropped this into my standard AHK script which runs at startup, used a different key (I normally use ^#! for my AHK hotkeys, but ^#!m is already used by Remember the Milk, so I used ^#!s, for swap) and it works great. I'm sorry I can't upvote; or rather, I upvoted but it doesn't count, because I have <15 reputation, so my opinion is recorded but not displayed.

      – ludinom
      Aug 25 '17 at 20:57













    • @Confuzing, very nice solution. Only one question, it's always started as left handed, do you know how to make it start as right handed by default. I was trying to change swap=false, but that doesn't help. Thanks!

      – electroid
      Oct 7 '18 at 15:14






    • 1





      @electroid Changing swap to true should have worked. But you could change the '#if !swap' to '#if swap', or probably even easier to just reverse them in Windows mouse settings.

      – Confuzing
      Oct 7 '18 at 15:58











    • @Confuzing, your solution change the #if !swap to #if swap working just fine! Thanks!

      – electroid
      Oct 7 '18 at 17:54
















    3














    Here is what I came up with for AHK. Just toggles rebinding the mouse buttons with ctrl+alt+m



    swap:
    swap=false

    ^!m::
    swap := !swap

    #if !swap
    RButton::LButton
    LButton::RButton





    share|improve this answer
























    • Thanks a lot! I hadn't had a chance to get back to this and write it myself, but you saved me the trouble. Sorry to put you to the trouble, I could have figured it out once you pointed me in the direction of AHK. I dropped this into my standard AHK script which runs at startup, used a different key (I normally use ^#! for my AHK hotkeys, but ^#!m is already used by Remember the Milk, so I used ^#!s, for swap) and it works great. I'm sorry I can't upvote; or rather, I upvoted but it doesn't count, because I have <15 reputation, so my opinion is recorded but not displayed.

      – ludinom
      Aug 25 '17 at 20:57













    • @Confuzing, very nice solution. Only one question, it's always started as left handed, do you know how to make it start as right handed by default. I was trying to change swap=false, but that doesn't help. Thanks!

      – electroid
      Oct 7 '18 at 15:14






    • 1





      @electroid Changing swap to true should have worked. But you could change the '#if !swap' to '#if swap', or probably even easier to just reverse them in Windows mouse settings.

      – Confuzing
      Oct 7 '18 at 15:58











    • @Confuzing, your solution change the #if !swap to #if swap working just fine! Thanks!

      – electroid
      Oct 7 '18 at 17:54














    3












    3








    3







    Here is what I came up with for AHK. Just toggles rebinding the mouse buttons with ctrl+alt+m



    swap:
    swap=false

    ^!m::
    swap := !swap

    #if !swap
    RButton::LButton
    LButton::RButton





    share|improve this answer













    Here is what I came up with for AHK. Just toggles rebinding the mouse buttons with ctrl+alt+m



    swap:
    swap=false

    ^!m::
    swap := !swap

    #if !swap
    RButton::LButton
    LButton::RButton






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 25 '17 at 13:49









    ConfuzingConfuzing

    43118




    43118













    • Thanks a lot! I hadn't had a chance to get back to this and write it myself, but you saved me the trouble. Sorry to put you to the trouble, I could have figured it out once you pointed me in the direction of AHK. I dropped this into my standard AHK script which runs at startup, used a different key (I normally use ^#! for my AHK hotkeys, but ^#!m is already used by Remember the Milk, so I used ^#!s, for swap) and it works great. I'm sorry I can't upvote; or rather, I upvoted but it doesn't count, because I have <15 reputation, so my opinion is recorded but not displayed.

      – ludinom
      Aug 25 '17 at 20:57













    • @Confuzing, very nice solution. Only one question, it's always started as left handed, do you know how to make it start as right handed by default. I was trying to change swap=false, but that doesn't help. Thanks!

      – electroid
      Oct 7 '18 at 15:14






    • 1





      @electroid Changing swap to true should have worked. But you could change the '#if !swap' to '#if swap', or probably even easier to just reverse them in Windows mouse settings.

      – Confuzing
      Oct 7 '18 at 15:58











    • @Confuzing, your solution change the #if !swap to #if swap working just fine! Thanks!

      – electroid
      Oct 7 '18 at 17:54



















    • Thanks a lot! I hadn't had a chance to get back to this and write it myself, but you saved me the trouble. Sorry to put you to the trouble, I could have figured it out once you pointed me in the direction of AHK. I dropped this into my standard AHK script which runs at startup, used a different key (I normally use ^#! for my AHK hotkeys, but ^#!m is already used by Remember the Milk, so I used ^#!s, for swap) and it works great. I'm sorry I can't upvote; or rather, I upvoted but it doesn't count, because I have <15 reputation, so my opinion is recorded but not displayed.

      – ludinom
      Aug 25 '17 at 20:57













    • @Confuzing, very nice solution. Only one question, it's always started as left handed, do you know how to make it start as right handed by default. I was trying to change swap=false, but that doesn't help. Thanks!

      – electroid
      Oct 7 '18 at 15:14






    • 1





      @electroid Changing swap to true should have worked. But you could change the '#if !swap' to '#if swap', or probably even easier to just reverse them in Windows mouse settings.

      – Confuzing
      Oct 7 '18 at 15:58











    • @Confuzing, your solution change the #if !swap to #if swap working just fine! Thanks!

      – electroid
      Oct 7 '18 at 17:54

















    Thanks a lot! I hadn't had a chance to get back to this and write it myself, but you saved me the trouble. Sorry to put you to the trouble, I could have figured it out once you pointed me in the direction of AHK. I dropped this into my standard AHK script which runs at startup, used a different key (I normally use ^#! for my AHK hotkeys, but ^#!m is already used by Remember the Milk, so I used ^#!s, for swap) and it works great. I'm sorry I can't upvote; or rather, I upvoted but it doesn't count, because I have <15 reputation, so my opinion is recorded but not displayed.

    – ludinom
    Aug 25 '17 at 20:57







    Thanks a lot! I hadn't had a chance to get back to this and write it myself, but you saved me the trouble. Sorry to put you to the trouble, I could have figured it out once you pointed me in the direction of AHK. I dropped this into my standard AHK script which runs at startup, used a different key (I normally use ^#! for my AHK hotkeys, but ^#!m is already used by Remember the Milk, so I used ^#!s, for swap) and it works great. I'm sorry I can't upvote; or rather, I upvoted but it doesn't count, because I have <15 reputation, so my opinion is recorded but not displayed.

    – ludinom
    Aug 25 '17 at 20:57















    @Confuzing, very nice solution. Only one question, it's always started as left handed, do you know how to make it start as right handed by default. I was trying to change swap=false, but that doesn't help. Thanks!

    – electroid
    Oct 7 '18 at 15:14





    @Confuzing, very nice solution. Only one question, it's always started as left handed, do you know how to make it start as right handed by default. I was trying to change swap=false, but that doesn't help. Thanks!

    – electroid
    Oct 7 '18 at 15:14




    1




    1





    @electroid Changing swap to true should have worked. But you could change the '#if !swap' to '#if swap', or probably even easier to just reverse them in Windows mouse settings.

    – Confuzing
    Oct 7 '18 at 15:58





    @electroid Changing swap to true should have worked. But you could change the '#if !swap' to '#if swap', or probably even easier to just reverse them in Windows mouse settings.

    – Confuzing
    Oct 7 '18 at 15:58













    @Confuzing, your solution change the #if !swap to #if swap working just fine! Thanks!

    – electroid
    Oct 7 '18 at 17:54





    @Confuzing, your solution change the #if !swap to #if swap working just fine! Thanks!

    – electroid
    Oct 7 '18 at 17:54













    1














    This is the answer, which was posted on https://superuser.com/a/1357020/790554.



    This is the Autohotkey version (modified/based on https://github.com/jNizM/AHK_DllCall_WinAPI/blob/master/src/Mouse%20Input%20Functions/SwapMouseButton.ahk).



    ; autohotkey code - mapped to F12
    F12::
    buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 1)
    if buttonState <> 0
    {
    buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 0)
    }


    This works fine with all Windows (including Windows 10). I usually map it to a hotkey such as "F12" key on my keyboard (using Autohotkey), and I can toggle between left and right mouse button instantly with press of a key.






    share|improve this answer




























      1














      This is the answer, which was posted on https://superuser.com/a/1357020/790554.



      This is the Autohotkey version (modified/based on https://github.com/jNizM/AHK_DllCall_WinAPI/blob/master/src/Mouse%20Input%20Functions/SwapMouseButton.ahk).



      ; autohotkey code - mapped to F12
      F12::
      buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 1)
      if buttonState <> 0
      {
      buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 0)
      }


      This works fine with all Windows (including Windows 10). I usually map it to a hotkey such as "F12" key on my keyboard (using Autohotkey), and I can toggle between left and right mouse button instantly with press of a key.






      share|improve this answer


























        1












        1








        1







        This is the answer, which was posted on https://superuser.com/a/1357020/790554.



        This is the Autohotkey version (modified/based on https://github.com/jNizM/AHK_DllCall_WinAPI/blob/master/src/Mouse%20Input%20Functions/SwapMouseButton.ahk).



        ; autohotkey code - mapped to F12
        F12::
        buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 1)
        if buttonState <> 0
        {
        buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 0)
        }


        This works fine with all Windows (including Windows 10). I usually map it to a hotkey such as "F12" key on my keyboard (using Autohotkey), and I can toggle between left and right mouse button instantly with press of a key.






        share|improve this answer













        This is the answer, which was posted on https://superuser.com/a/1357020/790554.



        This is the Autohotkey version (modified/based on https://github.com/jNizM/AHK_DllCall_WinAPI/blob/master/src/Mouse%20Input%20Functions/SwapMouseButton.ahk).



        ; autohotkey code - mapped to F12
        F12::
        buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 1)
        if buttonState <> 0
        {
        buttonState := DllCall("user32.dllSwapMouseButton", "UInt", 0)
        }


        This works fine with all Windows (including Windows 10). I usually map it to a hotkey such as "F12" key on my keyboard (using Autohotkey), and I can toggle between left and right mouse button instantly with press of a key.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 10 '18 at 20:20









        otter.prootter.pro

        415




        415






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1244084%2fhow-do-i-swap-primary-and-secondary-mouse-buttons-from-the-command-line-or-by-us%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How do I know what Microsoft account the skydrive app is syncing to?

            When does type information flow backwards in C++?

            Grease: Live!