Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when (forward) slash key is pressed in OEM keys C#

Tags:

c#

key

wpf

slash

I'm working on wpf c# application and I need to detect when user press "/" but I'm having trouble with finding " / " e.Key, I saw there is Key.OemBackslash and stuffs like that, but I can't find right event for " / " (forward slash) ...

Thanks guys, Cheers

like image 380
Roxy'Pro Avatar asked Feb 05 '17 23:02

Roxy'Pro


People also ask

Which key is forward slash?

On English keyboards, the forward slash is on the same key as the question mark key next to the right Shift key.

How do I fix my slash key?

Try the Keyboard Troubleshooter at Settings > Update & Security > Troubleshoot. Check also at Settings > Time & Language > Region & Language to make sure the correct Language appears, then choose Advanced Keyboard Settings to see if a different input method is chosen in the dropdown menu.

What is slash key?

Creating the \ symbol on a U.S. keyboard On English PC and Mac keyboards, the backslash key is also the pipe key. It is located above the Enter key (Return key), and below the Backspace key. Pressing \ key creates a backslash.


1 Answers

It should be Key.OemQuestion on a US keyboard. But on a Swedish keyboard it is D7 so it depends. The keys on the keyboard doesn't always produce the same character.

Depending on what you are trying to do you may be better off handling the PreviewTextInput event:

protected override void OnPreviewTextInput(TextCompositionEventArgs e)
{
    base.OnPreviewTextInput(e);
    if (e.Text == "/")
    {
        Debug.WriteLine("...");
    }
}
like image 157
mm8 Avatar answered Oct 19 '22 10:10

mm8