Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have to implement the keyboard shortcuts in my application
if i do ctrl+c then my connect function should be call
could you please suggest me

What I have tried:

i have added in my .rc file
IDR_MAINFRAME MENU
BEGIN
    POPUP "File"

MENUITEM "&Connect",                    ID_FILE_CONNECT

END


IDR_MAINFRAME ACCELERATORS
BEGIN
    "C",            ID_FILE_CONNECT,        VIRTKEY, CONTROL

END

im .cpp
ON_COMMAND(ID_FILE_CONNECT, OnFileConnect)

lstBasicCommands.AddTail(ID_FILE_CONNECT);

PostMessage(WM_COMMAND, ID_FILE_CONNECT);

could you please suggest me if anything is missed here
Posted
Updated 21-Jun-17 22:49pm
Comments
Richard MacCutchan 22-Jun-17 4:20am    
What happens when you run the app and type Ctrl+C?

1 solution

Should work that way in general.

But Ctrl+C is the shortcut for ID_EDIT_COPY. If the focus is on a control that supports that shortcut, it will be handled by the control and not by the main frame window.

I suggest to select a shortcut that is not a general one (listed at Keyboard shortcuts for Windows[^]).

[EDIT]
See also the topic "Provide consistent keyboard shortcuts" at Guidelines for Keyboard User Interface Design (Windows)[^]:
Quote:
A consistent keyboard UI between applications helps users to learn and interact with new applications. An application must not affect any system-wide shortcut keys (a key or a combination of keys used to perform a command), such as the Windows logo key that opens the Start menu. An application must also follow commonly recognized shortcut key assignments, such as CTRL+C for Copy and CTRL+Z for Undo.
[/EDIT]
 
Share this answer
 
v2
Comments
Member 13089825 22-Jun-17 8:58am    
thank you jochen for your quick reply.
is it possible to implement own shortcuts(i mean override existing one with new one)
Jochen Arndt 22-Jun-17 9:29am    
You can do that. But then you have to override it in all windows that handle the shortcut by default.

But again: I would not do so. It is breaking the usability guidelines (I will update my answer with a link).

Many users know that Ctrl+C is the shortcut to copy the actually selected data to the clipboard and will assume that an application handles it as expected. They might be irritated or annoyed if your application behaves differently.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900