Welcome to EMC Consulting Blogs Sign in | Join | Help

Rob Henry's Blog

Visual Studio - Keyboard Shortcuts for Debug Tool Tips

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, ahk 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

Published 23 November 2008 20:13 by Rob.Henry

Comments

 

simon.munro said:

For those who haven't seen Rob working, I have to point out that 'avoid(ing) using the mouse as much as possible' is a bit of an understatement.  Rob doesn't even have the frikkin mouse plugged in and if you have to do something on his machine you will grab a dead mouse before saying 'ok, you drive'.  So Rob knows keyboard shortcuts - end of story.  If he could hook up foot pedals he would, those few milliseconds it takes to reach for the mouse seem to get in the way of coding.

November 24, 2008 09:13
 

Rob.Henry said:

Foot pedals. That would be quality!

November 24, 2008 13:45
 

Daniel Moth said:

TIP: VS keyboard shortcut for editor tooltip

December 4, 2008 02:20
 

stevec said:

I'm doing something wrong ... all I get is a letter "n" typed in   :-(

- VS2008 SP1

- AutoHotkey 1.0.47.06

December 9, 2008 11:47
 

Rob.Henry said:

Steve, Try to restart AutoHotkey to solve this. If you still have a problem you can email me your AutoHotkey script and I'll take a look.

December 9, 2008 13:15
Anonymous comments are disabled
Powered by Community Server (Personal Edition), by Telligent Systems