Emulate a button pressed when mouse is clicked

katredrum
katredrum used Ask the Experts™
on
Hello Experts,

I would like to know if there's a way to emulate pressing a key or spacebar button when I click my mouse. I looked under the mouse controls and didn't natively find a way to do so. I would like to run this in both Windows XP and 7.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Absolutely, it's called remapping and here's how:

http://www.autohotkey.com/docs/misc/Remap.htm
IT Manager
Top Expert 2010
Commented:
1.  Install XMouseControl from http://www.highrez.co.uk/downloads/XMouseButtonControl.htm

2. Change your designated mouse click to "Simulated Keys" such as {SPACE}

Reference
http://www.overclock.net/t/401480/alternative-to-logitech-setpoint

Author

Commented:
Exactly what I needed! Thank you!
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Jackie Man IT Manager
Top Expert 2010

Commented:
Glad to know that you have solved the problem.

Commented:
So how's that better than http://www.AutoHotkey.com ? Why not accept the first answer?
Jackie Man IT Manager
Top Expert 2010

Commented:
Hi Christian,

If you try my solution, you will know the reason.

Author

Commented:
kinecsys, i wanted to split the points but it wasn't a really a solution. I looked at your site and didn't get know how to configure it. For me, it wasn't a solution. jackieman's solution was easy to install and configure.

Author

Commented:
kinecsys, I tried your suggested solution again today and still don't understand how to configure it. There are no instructions on how to do anything. Can you post how to do what I'm trying to do?

Commented:
First of all, no disrespect to Jackieman at all, the app you suggested works great. I just feel like it's only fair to accept the first full and correct answer.

Katredrum: If you download my suggested app from the original link I posted or from this direct download link:

http://www.autohotkey.com/download/AutoHotkeyInstall.exe

then all you have to do is run it and add a single line of text to the script according to what keys/buttons you want to remap.

Just go to your My Documents folder, find the "AutoHotkey.ahk" file, right click it and select "Edit Script".

Once the script is open, scroll down a little to where you see these two lines:

#z::Run www.autohotkey.com

^!n::

Open in new window


then add a third line with your desired mapping.  The sytntax is

source::target

Open in new window


Where source is the key or button that you will hit and target is the action that will be performed by that button or key.

Here's what my AutoHotkey.ahk file looks like:

; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments.  They are not executed.

; This script has a special filename and path because it is automatically
; launched when you run the program directly.  Also, any text file whose
; name ends in .ahk is associated with the program, which means that it
; can be launched simply by double-clicking it.  You can have as many .ahk
; files as you want, located in any folder.  You can also run more than
; one ahk file simultaneously and each will get its own tray icon.

; SAMPLE HOTKEYS: Below are two sample hotkeys.  The first is Win+Z and it
; launches a web site in the default browser.  The second is Control+Alt+N
; and it launches a new Notepad window (or activates an existing one).  To
; try out these hotkeys, run AutoHotkey again, which will load this file.

#z::Run www.autohotkey.com

^!n::

LButton::a
a::b
Mbutton::Rbutton
Rbutton::Lbutton


IfWinExist Untitled - Notepad
	WinActivate
else
	Run Notepad
return


; Note: From now on whenever you run AutoHotkey directly, this script
; will be loaded.  So feel free to customize it to suit your needs.

; Please read the QUICK-START TUTORIAL near the top of the help file.
; It explains how to perform common automation tasks such as sending
; keystrokes and mouse clicks.  It also explains more about hotkeys.

Open in new window


As you can see, I added four lines of code as examples for you, but you can add as many as you want or just a single line with your desired mapping.

The first line I added is LButton::a and it causes the left mouse button to act like the "a" key.

The second one is a::b and it causes the "a" key on the keyboard to act like the "b" key.

The third one is Mbutton::Rbutton and it causes the middle mouse click to act like the right mouse click.

And the fourth one is Rbutton::Lbutton and it causes the right mouse click to act like the left mouse click.

Once you've added your desired command, save the file and run the AutoHotKey app. It runs in the background always converting your input into whatever the script says. The sky is the limit.

FOR A FULL LIST OF COMMANDS LOOK THROUGH THE HELP FILE WHICH CONTAINS TONS OF INFO. WITH AUTOHOTKEY YOU CAN AUTOMATE TONS OF PROCESSES, FROM OPENING WEBSITES AND APPLICATIONS TO EXECUTING ADMINISTRATIVE COMPUTER TASKS WITH A SINGLE KEY COMBINATION.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial