Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

change mouse from right hand to left hand

1,712 views
Skip to first unread message

Jeremy

unread,
Feb 28, 2008, 7:37:01 PM2/28/08
to
I want to create a script to that allows a user to change the 'hand' setting
of the mouse. (Right handed user or left handed user).
Users do not have access to the control panel. Can I do this with a a
simple batch file or will I likely have to create a wmi type vbscript?
Thanks,


Herbert Kleebauer

unread,
Feb 29, 2008, 7:22:52 AM2/29/08
to

It's only 8 assembly instruction:

winmain::
moveq.l #0,-(sp)
jsr.l (SwapMouseButton)
eorq.l #1,r0
beq.b _10
move.l r0,-(sp)
jsr.l (SwapMouseButton)
_10: moveq.l #0,-(sp)
jsr.l (ExitProcess)

The following batch will generate "swap.exe". If swap.exe is executed,
the left and right mouse buttons are exchanged. The batch (the generation
of swap.exe) will only work in 32 bit Windows (because 64 bit Windows
doesn't support com files till now), but the swap.exe program itself
should also work in 64 bit Windows.


@echo off
echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>swap.com
echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>swap.com
echo wvPp0wv62k9C5/R/pN0d0uz627bwo1YiTAEWtbGov5//B6mkuMEo0IL0l/w>>swap.com
echo ef2iC57R/pNEA/jeefHhC5AR/pNEA/juefXgC5ER/phCfDM@m042knfuurC>>swap.com
echo U0F7l3Bd4M03E333lzzP/M0AF0/BV7U5V2Tcf2/EP1B61i0kInVsIOXJ57o>>swap.com
echo x57hJKNo0mQjpKNWx5Nt0mRcx57dB67nFLOgl57pBLOiR573xoIgoU1WJ6R>>swap.com
echo UUKOn01QmxqNm4KPU7LNlJLOmJqQUQJOiBXAioU1Y//I4N/H03//EZLdqAl>>swap.com
echo 0U2k20gE/4k//1AF1K1F3E307G/Y0E3V/5Ek35Ek36/G31AF01A00EM/3G/>>swap.com
echo V0EAF0EAV1E/V0wAlIEM/3HcV@oJ5So4VgG/F313V/Ho/75/y3z/53HI/WE>>swap.com
echo AF0M0l38k33F/V0/1l387635U/3HIFJHJYIn7X@Yl5P5/53HQkIr45QBxKR>>swap.com
echo nJaEpF6Rjt5/@JYICJ3Hn7X@Yl5P5U73HQEFsZ5RE8rPXJqQn0UO/wT4//0>>swap.com
echo E/A7w0Er0ExT4//0E/c5/zL01E/o3zDVH.>>swap.com
swap.com>swap.exe
del swap.com

Luuk

unread,
Feb 29, 2008, 3:58:41 PM2/29/08
to
Jeremy schreef:


if you create two .reg files

[swap0.reg]:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Control Panel\Mouse]
"SwapMouseButtons"="0"


[swap1.reg]:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Control Panel\Mouse]
"SwapMouseButtons"="1"

after that
C:\>regedit /s swap1.reg
will cause the mouse buttons to be swapped, but a logoff/logon is
required before change takes effect.

C:\>regedit /s swap0.reg
will restore settings, again a logoff/logon is required.

this should also work on 64-bit systems ..., but is not tested on
64-bit! ;-)

another disadvantage is that is user has no access to control panel,
he/she will probably also not have access to REGEDIT.EXE


--
Luuk

Clay Calvert

unread,
Feb 29, 2008, 9:19:18 PM2/29/08
to
On Fri, 29 Feb 2008 00:37:01 GMT, "Jeremy" <js...@nospamhotmail.com>
wrote:

This will let you swap one time. For some unknow reason it won't let
you set it back, at least in the current login session.

RUNDLL32.EXE USER32.DLL,SwapMouseButton

Just curious. See if one of the locked down accounts can run this
command to bring up just the Mouse applet, though I doubt it.

RUNDLL32.EXE SHELL32.dll,Control_RunDLL main.cpl @0,0

To follow on what Luuk suggested. Here is a script that uses Reg, as
opposed to Regedit, for toggling mouse buttons. A log off/on is also
required.

set Mous="HKCU\Control Panel\Mouse" /v SwapMouseButtons

for /f "tokens=3" %%a in ('reg query %Mous% ^|find "_SZ"') do (
set /a Button=%%a ^^ 1)

reg add %Mous% /d %Button% /f

Herbert Kleebauer

unread,
Mar 1, 2008, 4:54:55 AM3/1/08
to
Clay Calvert wrote:

> This will let you swap one time. For some unknow reason it won't let
> you set it back, at least in the current login session.
>
> RUNDLL32.EXE USER32.DLL,SwapMouseButton

SwapMouseButton requires a binary parameter (true/false) on the
stack. And as far as I remember, rundll don't let you specify
the parameters on the stack. Therefore SwapMouseButton takes
what ever is on the stack as parameter and that seems to not be
0 (false).

Luuk

unread,
Mar 1, 2008, 5:52:59 AM3/1/08
to
Herbert Kleebauer schreef:

Where did you get the info about this binary parameter?

The first 10 links or so of (http://tinyurl.com/yo6xau) do not mention
anything about this....

--
Luuk

Herbert Kleebauer

unread,
Mar 1, 2008, 12:09:16 PM3/1/08
to
Luuk wrote:
> Herbert Kleebauer schreef:


> Where did you get the info about this binary parameter?

http://msdn2.microsoft.com/en-us/library/ms646264.aspx

SwapMouseButton Function

The SwapMouseButton function reverses or restores the
meaning of the left and right mouse buttons.

Syntax

BOOL SwapMouseButton(
BOOL fSwap
);

Parameters

fSwap [in]

Specifies whether the mouse button meanings are reversed
or restored. If this parameter is TRUE, the left button
generates right-button messages and the right button
generates left-button messages. If this parameter is
FALSE, the buttons are restored to their original meanings.

Return Value

If the meaning of the mouse buttons was reversed previously,
before the function was called, the return value is nonzero.

If the meaning of the mouse buttons was not reversed, the
return value is zero.

Remarks

Button swapping is provided as a convenience to people who
use the mouse with their left hands. The SwapMouseButton
function is usually called by Control Panel only. Although
an application is free to call the function, the mouse is
a shared resource and reversing the meaning of its buttons
affects all applications.

Function Information

Minimum DLL Version user32.dll
Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode version.

See Also

Mouse Input, SetDoubleClickTime

Jeremy

unread,
Mar 1, 2008, 12:09:07 PM3/1/08
to

> another disadvantage is that is user has no access to control panel,
> he/she will probably also not have access to REGEDIT.EXE
Thank you Luuk. I think that I can log on as an administrator and give them
ntfs rights to use regedit.exe and for those specific registry entries (if
necessary). So I think I'll go with your suggestion. Thanks!
>
> --
> Luuk


co ,nz,

unread,
Apr 2, 2008, 11:53:35 PM4/2/08
to
On Feb 29, 5:37 am, "Jeremy" <j...@nospamhotmail.com> wrote:
> I want to create a script to that allows a user tochangethe 'hand' setting
> of themouse.  (Righthanded user or left handed user).

> Users do not have access to the control panel.  Can I do this with a a
> simple batch file or will I likely have to create a wmi type vbscript?
> Thanks,

Hi Jeremy,

This is ugly, but works surprisingly well. Its the only way, after
much searching, that I could find to do it with a VBscript.
'------------------------------------------------------------------
'------------------------------------------------------------------

Function SwapMouseButtons
oShell.Run "RUNDLL32.EXE SHELL32.dll,Control_RunDLL main.cpl @0,0"
WScript.Sleep 200
oShell.SendKeys "%S"
oShell.SendKeys "{Enter}"
End Function

Function SetMouseLeftHanded
x = oShell.RegRead("HKCU\Control Panel\Mouse\SwapMouseButtons")
if x=1 then SwapMouseButtons
End Function

Function SetMouseRightHanded
x = oShell.RegRead("HKCU\Control Panel\Mouse\SwapMouseButtons")
if x=0 then SwapMouseButtons
End Function


Alternativly, you could write a VBscript that directly calls the WIN
API using dynwrap.dll, that would be more robust, but requires extra
files and more complicated code.
Depends on taste and who has to maintain what you write.

Take care,

Julz.

solid...@gmail.com

unread,
Oct 31, 2013, 8:52:20 AM10/31/13
to
Sir, I cannot thank you enough. My workspace requires moving my mouse from right to left side of my machine very frequently. Until today I had to change the settings every single time. It was extremely frustrating.
Your solution works much, much faster than opening the mouse applet in Control Panel. Once again, thank you.

Solidstach

marcp...@hotmail.com

unread,
Feb 25, 2016, 7:22:25 AM2/25/16
to
Hi,

I liked your reply very much as I am looking for the same thing. But I don't know howto use the functions you provided.
Basically if I use this code:

Function SwapMouseButtons
oShell.Run "RUNDLL32.EXE SHELL32.dll,Control_RunDLL main.cpl @0,0"
WScript.Sleep 200
oShell.SendKeys "%S"
oShell.SendKeys "{Enter}"
End Function

Function SetMouseLeftHanded
x = oShell.RegRead("HKCU\Control Panel\Mouse\SwapMouseButtons")
if x=1 then SwapMouseButtons
End Function

Function SetMouseRightHanded
x = oShell.RegRead("HKCU\Control Panel\Mouse\SwapMouseButtons")
if x=0 then SwapMouseButtons
End Function

How can I use it? Save as BAT file and run?

Thanks for your help.

foxidrive

unread,
Feb 25, 2016, 7:40:13 AM2/25/16
to
On 25/02/2016 23:22, marcp...@hotmail.com wrote:

> Function SetMouseRightHanded
> x = oShell.RegRead("HKCU\Control Panel\Mouse\SwapMouseButtons")
> if x=0 then SwapMouseButtons
> End Function
>
> How can I use it? Save as BAT file and run?

It is to be used in a .vbs script but extra lines are needed.

The top link here show you how to create an executable on modern windows
for it, with no extra programs needed.

http://stackoverflow.com/questions/4806575/how-do-i-use-rundll32-to-swapmousebutton

The cnet link has a pre-built utility - I haven't tried it.

http://download.cnet.com/SwapMouseButtons/3000-2056_4-10053869.html

Autohotkey is my favourite automation tool using hotkeys and hotstrings.
I use the features many times daily

https://autohotkey.com/board/topic/57504-swapmousebuttons-function/

I searched using this term:

https://www.google.com.au/search?q=Function+SwapMouseButtons



Herbert Kleebauer

unread,
Feb 25, 2016, 10:20:50 AM2/25/16
to
On 25.02.2016 13:22, marcp...@hotmail.com wrote:

Save as BAT file and run?

A few lines of assembly code will do it:

winmain::
moveq.l #0,-(sp)
jsr.l (SwapMouseButton)
eorq.l #1,r0
beq.b _10
move.l r0,-(sp)
jsr.l (SwapMouseButton)
_10: moveq.l #0,-(sp)
jsr.l (ExitProcess)



The binary included in a batch file:


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@echo off
:: swap left and right mouse button

certutil -f -decode %~f0 swap.exe>nul
swap.exe
del swap.exe

goto :eof

-----BEGIN CERTIFICATE-----
TVpgAQEAAAAEAAAA//8AAGABAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAoAAAAA4fug4AtAnNIbgBTM0hTmljZSB0byBtZWV0IHNvbWVi
b2R5IHdobyBpcyBzdGlsbCB1c2luZyBET1MsDQpidXQgdGhpcyBwcm9ncmFtIHJl
cXVpcmVzIFdpbjMyLg0KJFBFAABMAQEAUHmlNgAAA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AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAA==
-----END CERTIFICATE-----



Kerr Mudd-John

unread,
Feb 29, 2016, 3:11:47 PM2/29/16
to
On Thu, 25 Feb 2016 12:40:10 -0000, foxidrive <foxi...@server.invalid>
wrote:
It's a simple clobber of a regkey so you could:

reg add "HKCU\Control Panel\Mouse" /v SwapMouseButtons /d 1 /f

but I don't think it comes into effect immediately.

--
Bah, and indeed, Humbug
0 new messages