Commenting via shortcut keys in VFP

Tagged:

The comment/uncomment items on the Format menu do not have shortcut keys but they have access keys assigned. Pressing ALT+om and ALT+on on a keyboard will comment/uncomment selected text respectively.

Rick shows in his blog Commenting via ShortCut Key in Visual FoxPro how to implement MS VS shortcut keys CTRL+K+C and CTRL+K+U to comment/uncomment code using KEYBOARD command. The same can be done with Editor functions from Foxtools.fll. It gives more control over the process, like checking if anything is selected, etc.
See George Tasker's Extended Foxtools Help Download #9333 on UT for more info.

This is sample code. Add error handling and adjust to your requirements as necessary.

ON KEY LABEL CTRL+K do VsStyleComment
...
 
FUNCTION VsStyleComment
LOCAL lnKey, lnWhandle
 
lnKey = INKEY(.5,"HM")
lnWhandle = _WonTop()
 
DO CASE
CASE lnKey = 3  && Ctrl-C
	= _EdComment(lnWhandle, 1)
CASE lnKey = 21  && Ctrl-U
	= _EdComment(lnWhandle, -1)
ENDCASE
ENDFUNC
 
FUNCTION _WonTop
SET LIBRARY TO FoxTools ADDITIVE
RETURN = _WonTop()
ENDFUNC

See Also Copy Command Window Selected Text to Clipboard programmatically, Changing Command Window Font Programmatically, Copy PRG contents to Clipboard