When using Visual Studio I try to avoid using the mouse as much as possible, however there are some functions, such as debug tool tips, that can't be mapped to keystrokes. These neat tool tips allow Visual Studio to display the value of variables when you hover over them with your mouse. I like to leave my code editing window with as much screen space as possible so I try not to have windows pinned open if I can avoid it (more on this in another post). If I don't have one of the debug windows open and I want to quickly see what value a variable has I need to grab for the mouse, which can be frustrating.
After finding that a keystroke couldn't be mapped to display the debug tool tips I decided to look towards AutoHotkey, which among other things, allows a user to write a script to simulate keystrokes and mouse movements. I created a script in AutoHotkey that moves the mouse cursor to the position of the text cursor on a keystroke. The script is quite simple and I've described the steps below:
The Script
1 #IfWinActive, ,Visual Studio
2 #n::
3 MouseGetPos ,currentX, currentY
4 MouseMove, A_CaretX, A_CaretY + 15
5 KeyWait, LWin
6 MouseMove, currentX, currentY
7 return
Line 1 - Checks that the current window is Visual Studio.
Line 2 - Checks that the keystroke is the windows key + n.
Line 3 - Gets the current position of the mouse cursor and assigns the x and y values to currentX and currentY. The + 15 allows them to line up evenly.
Line 4 - Moves the mouse cursor to the current position of the text cursor, which will cause Visual Studio to display the tool tip.
Line 5 - Wait for the windows key to be released.
Line 6 - Moves the mouse back to its original position.
Limitations
This script will allow you to quickly move around and display the value of the variable you're hovering over, but it won't allow you to drill down through the object tree. Therefore, if I need to do something a bit more in depth I'm happy enough to open a Quick Watch window with Ctrl+Alt+Q.
Using the Script
To use this script take the following steps:
- Install AutoHotkey.
- Right click the AutoHotkey icon in the system tray,
and select "Edit This Script".
- Paste the script into the main script and save.
- Right click the AutoHotkey icon again and select "Reload This Script".
To use this script in Visual Studio: Move your keyboard cursor over the variable you wish to see the value of, and hold down the windows key + n. The mouse cursor will temporarily move over the variable and display the tool tip. When you release the windows key the mouse cursor will return to its original position and the tool tip will disappear.
AutoHotkey is a powerful tool and I hope, even if you mostly use your mouse, you can see that it could be a neat solution to other tasks that require keyboard or mouse automation.
For more Developer productivity tips you can visit my other blog - The Home Row