Making Use of Shortcut Keys

Making Use of Shortcut Keys

“Send a Message” (Windows Programming, by Jonathan Zuck,VBPJ December 1995), a great example of code usable ina text editor, mentions three ways to code the Clipboard functionsusing SendMessage, VB’s Clipboard object, or SendKeys. The Clipboardobject requires hand-coding with the SelText property. SendMessageand the Clipboard object require you to specify which text boxis being edited, demanding the ActiveControl property if you havemore than one text box on the form. Clearly the easiest methodis to use SendKeys for Undo (^Z), Delete (Del), Cut (^X), Copy(^C), and Paste (^V), the functions Windows implements natively.

In the Edit menu you’ll probably want to assign Shortcut keysto these functions, so the control codes are shown to the rightfor users as in most Windows applications’ Edit menus:

 Undo            Ctrl+Z**************Delete           DelCut                 Ctrl+XCopy               Ctrl+CPaste             Ctrl+V

The functions no longer work if your Edit menu has Shortcut keysassigned like this and the Edit subs use SendKeys to access thebuilt-in Windows text-box editing functions. The ^X, ^C, ^V, Del,and ^Z keystrokes are captured by the Edit menu shortcuts andso are never processed. You could use SendMessage, mimic the functionsin VB codes using the Clipboard object, or leave off the Shortcutkeys.

All this seems unnecessary. Windows has the functions built inand I want only to show the shortcuts on the menu so users knowwhat they are. An easy solution is to launch the Notepad, typea Tab, then copy the Tab to the clipboard. Next, open the MenuDesign Window and paste the Tab character followed by the shortcuttext in the menu’s Caption property:

 Caption: &Copy[paste tabchar]Ctrl+C

or:

 Caption: &Undo[paste tabchar]Ctrl+Z

Set the Shortcut to (none). Now put the simple SendKeys “^C”in Sub mnuEditCopy and it works!

A design-time problem with this method occurs if you leave thatmenu item and return to it. VB then chops off the Caption at theTab character and you lose your shortcut text. You must repastethe Tab and retype the control code. Or, you could use a menuarray and Load menu items at run time with embedded Tab characters:

 Load mnuEditArray(1)mnuEditArray(1).Caption = "&Undo" _        & Chr$(9) & "Ctrl+Z"

I dislike doing anything in code that can be done at design time,so I prefer the former method and avoid clicking on the affectedmenu items.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as