KEYS ENUMERATOR

Giorgio Sfiligoi 391 Reputation points
2022-09-15T11:59:24.21+00:00

I have not been able to find the 'lower than' (<) and 'greater than' (>) symbols in the Keys enumerator.
I need to capture keystrokes from the user, such as:

    private void listTransactions_KeyDown(object sender, KeyEventArgs e)  
    {  
        if (e.Control)  
        {  
            int index = -1;  
            switch (e.KeyCode)  
            {  
                ...  
                case Keys.Oemcomma: index = 2; break;   // <  
                case Keys.OemPeriod: index = 3; break;     //  >  
                ...  
            }  
            e.Handled = true;  
        }  
    }  

In the US keyboard the < > symbols are associated with comma and period, thus I used these codes - taking advantage from the fact that the Control modifier is Shift-insensitive.

However, a different keyboard layout will have the < > symbols on other keys: e.g. the IT layout locates them together in a single key.

So my code will not be able to support different layouts?

I also tried:

            switch (e.KeyValue)  
            {  
                ...  
                case '<': index = 2; break;  
                case '>': index = 3; break;  
                ...  
            }  

but it does not work.

Developer technologies | Windows Forms
Windows development | Windows API - Win32
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2022-09-15T13:32:08.947+00:00

    I think that it is better to handle the KeyPress event, where e.KeyChar will be '<'.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.