I work a lot in Visual Studio and when I return to FoxPro one thing I really miss is the instant ability..." />
Rick Strahl's FoxPro and Web Connection Web Log

Commenting via ShortCut Key in Visual FoxPro

Wednesday, February 20, 2008, 12:37:00 PM

I work a lot in Visual Studio and when I return to FoxPro one thing I really miss is the instant ability to comment code with a keystroke. I keep finding myself pressing the VS comment sequence - Ctrl-K-C and Ctrl-K-U - constantly and being frustrated that nothing happens. <g>


Then I remember where I'm at and I curse the Comment options on the Context menu – you know right click a selection and select comment/uncomment. Many times the menu option is scrolled off the FoxPro IDE window so you can't even select it. Other times I don't even get as far: Instead of the Context dropdown I get the Move/Copy dropdown presumably because I moved the mouse around slightly before clicking. Grrr…


Anyway in Visual FoxPro commenting is handled via menu options on the Format menu. The problem is that Comment and Uncomment aren't directly hotkeyed via shortcut keys and there's no programmatic menu pad definition so you can't directly assign an operation to activate the menu option either.


However, you CAN of course use the menu hotkey combinations: Alt-O-m and Alt-O-n respectively. Now this may seem real obvious to some but uhm I never really picked that up in all the years of Fox coding. Duh! Thanks to Sergey on the UT for pointing out the obvious when I asked how to automate the process.


What I really want to do though is simulate my key reflex for Ctrl-K-c and Ctrl-K-u which I have gotten insanely used to from Visual Studio work (in all environments from ASP.NET markup, to C# to JavaScript).


My first thought was to apply a On Key Label command, but that doesn't quite get you there because ON KEY LABEL only understands two finger cords.


With a little trickery however it's possible to do the following:


ON KEY LABEL CTRL+K do VsStyleComment in PROGRAM()


FUNCTION VsStyleComment


lnKey = INKEY(.5,"HM")

IF lnKey = 3  && Ctrl-C

      KEYBOARD "{ALT+o}m"


IF lnKey = 21  && Ctrl-U

      KEYBOARD "{ALT+o}n"





And this does the trick. Now it'd be nice to do a little extra checking of menus and to ensure that the menu exists, but heck this is good enough for now.

Posted in:

Feedback for this Weblog Entry

Re: Commenting via ShortCut Key in Visual FoxPro

Well if Craig Boyd has his way, soon you be able to use the VS2008 shell to write VFP code. I don't know, but, I'm assuming that the Ctrl-K-c/u is going to work the way you like? Here hoping...

Re: Commenting via ShortCut Key in Visual FoxPro

Sylvain Bujold
I'm the type of person that tries to avoid the mouse as much as I can, so I learned to use the context-menu key a lot, so in vfp I always comment using context-menu+m our context-menu+n to uncomment. This has always worked very well for me.

Of course it depends on where it's located on your keyboard, some keyboard have it too far to be useful, especially on laptops, but my external keyboard has it on the right-side under the shift key so it's easy to access.


© Rick Strahl, West Wind Technologies, 2003 - 2018