Commenting via ShortCut Key in Visual FoxPro
February 20, 2008 •
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"
ENDIF
IF lnKey = 21 && Ctrl-U
KEYBOARD "{ALT+o}n"
ENDIF
ENDFUNC
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.
Mike
February 20, 2008