Laxmi
Laxmi

Reputation: 93

How to capture Ctrl-V or enable Right Click Paste option with the KeyDown event of a TextBox in UWP

I am trying to paste an image in TextBox on either user presses Ctrl + V shortcut or right-click and select paste option. I tried this method to capture the keyboard key but it only works if I enter V

if(e.Key == Windows.System.VirtualKey.V)

How to capture Ctrl + V both keyboard keys. In my case, this is not working

if (e.Key == Windows.System.VirtualKey.V && e.Key == Windows.System.VirtualKey.Control)  

Upvotes: 0

Views: 550

Answers (1)

user13387451
user13387451

Reputation:

In order to capture the control key, you need to check the HasFlag property.

var controlDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
    
if (controlDown & e.Key == Windows.System.VirtualKey.V)
{
    
}

Upvotes: 2

Related Questions