testalino
testalino

Reputation: 5668

Ctrl + C on Textbox does not work because of global shortcut

I created a numeric textbox and want to implement a custom copy/paste functionality.

When override ProcessCmdKey, OnKeyDown or OnKeyPress Ctrl+C is not received, because there is a shortcut in the application defined with the same combination.

Other combinations like Ctrl+U or whatever are received.

Is this even possible? How?

Upvotes: 2

Views: 1820

Answers (4)

Alban
Alban

Reputation: 1

For me the answer that was striked out worked well. I actually found the solution myself and implemented it but didn't go to compiling for testing, and decided to look for help because the IsInputKey is a very strange name to say that you want to capture the key down.

Upvotes: 0

A.R.
A.R.

Reputation: 15705

As Florian pointed out, the message is getting eaten inside of the control somehow, and as you have no direct access to it, you will have to get clever.

This library may be of some use to you, but you will be getting into pretty hacky territory with it as you will have to avoid your normal events (like OnPreviewKeyDown), and use the ones from the lib instead.

http://www.codeproject.com/KB/cs/globalhook.aspx

However if you are trying to capture ctrl+C yourself and do something with it, this is a route you may want to avoid. Users will not expect two things to happen when they hit a shortcut, and they will come after you. Of course, I don't know how or what your app does so that is just a guess.

Upvotes: 1

seairth
seairth

Reputation: 2062

Set ShortcutsEnabled to false on the control. See TextBoxBase.ShortcutsEnabled.

Upvotes: 0

Florian Greinacher
Florian Greinacher

Reputation: 14784

In this case you should override Control.OnPreviewKeyDown and for the case that Ctrl + C is pressed set PreviewKeyDownEventArgs.IsInputKey to true. Doing this should cause Control.OnKeyDown to be called although there is a global shortcut for this key combination.

Update: As my solution does not work for you, the third party library obviously implemented an IMessageFilter which causes the shortcuts to be handled at the message level. You could try to add another message filter and do your custom handling there, nevertheless this will now get ugly...

Upvotes: 3

Related Questions