CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    May 2002
    Posts
    171

    How to detect ctrl-c pressed?

    I created a new dialog based project and added OnKeyDown() message handler, but no matter what I pressed, it never got called?

  2. #2
    Join Date
    Jul 2002
    Posts
    372

    Re: How to detect ctrl-c pressed?

    override PreTranslateMessage and do:

    Code:
    BOOL CDlg::PreTranslateMessage(MSG* pMsg) 
    {
    	if( pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x43 && GetKeyState( VK_CONTROL ) < 0 ) {
    		_asm int 3
    	}
    
    	return CDialog::PreTranslateMessage(pMsg);
    }
    regards
    Last edited by neo_the_1; August 15th, 2005 at 05:31 PM.

  3. #3
    Join Date
    May 2002
    Posts
    171

    Re: How to detect ctrl-c pressed?

    when I used your code and press ctrl-c, the code inside got executed when the "ctrl" key was hold, and nothing happened after "c" pressed.

  4. #4
    Join Date
    Jul 2002
    Posts
    372

    Re: How to detect ctrl-c pressed?

    try again i have made a change.

  5. #5
    Join Date
    May 2002
    Posts
    171

    Re: How to detect ctrl-c pressed?

    Thanks that works. so 0x43 is the virtual key code for ctrl-c? how about ctrl-v? where did you find the table?

  6. #6
    Join Date
    Jul 2002
    Posts
    372

    Re: How to detect ctrl-c pressed?

    Virtual-Key Codes from MSDN.
    Enjoy.

  7. #7
    Join Date
    May 2002
    Posts
    171

    Re: How to detect ctrl-c pressed?

    This approach works for CDialog, I assume it works the same way in CView. However, when I out the CView into ActiveX Control, it never got called. Do you know why?

  8. #8
    Join Date
    May 2005
    Posts
    4,954

    Re: How to detect ctrl-c pressed?

    Quote Originally Posted by tangjun
    This approach works for CDialog, I assume it works the same way in CView. However, when I out the CView into ActiveX Control, it never got called. Do you know why?
    it never get called cause this ActiveX probably not handling Ctrl+C key press. only the the window that Handle it can get it while it in focus of course.
    if you want to detect Ctrl+C in all the system no matter what window is active (at the moment ) you can consider using ::SetWindowsHookEx (..) with WH_KEYBOARD parameter to check it out.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  9. #9
    Join Date
    May 2002
    Posts
    171

    Re: How to detect ctrl-c pressed?

    However, the OnKeyDown() does get called in activeX control. Can you detect ctrl-c with OnKeyDown()?


    I don't want to set it system wide because there are other window than the activex control in the system which is using the contrl-c.
    Last edited by tangjun; August 16th, 2005 at 11:10 AM.

  10. #10
    Join Date
    Jul 2003
    Posts
    147

    Re: How to detect ctrl-c pressed?

    Why don't you just setup an Accelerator to handle Ctrl+C?

  11. #11
    Join Date
    May 2002
    Posts
    171

    Re: How to detect ctrl-c pressed?

    how? sample code please?

  12. #12
    Join Date
    May 2005
    Posts
    4,954

    Re: How to detect ctrl-c pressed?

    Quote Originally Posted by tangjun
    However, the OnKeyDown() does get called in activeX control. Can you detect ctrl-c with OnKeyDown()?


    I don't want to set it system wide because there are other window than the activex control in the system which is using the contrl-c.
    if you want a system wide then OnKeyDown() is not the correct way. i wrote in my post before if you want a system wide keybaord hook you need to use ::SetWindowsHookEx(..) with WH_KEYBOARD.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  13. #13
    Join Date
    May 2002
    Posts
    171

    Re: How to detect ctrl-c pressed?

    no, I don't want system wide, my system will have more than one activex control, each one should handle the control-c by itself. so if ctrl-c pressed, the highlighted one should get called.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured