0

I'm currently learning C# in University and I was wondering where you would use KeyValue. From this question (https://stackoverflow.com/a/318177), I found that "KeyCode is an enumeration that represents all the possible keys on the keyboard. KeyData is the KeyCode combined with the modifiers (Ctrl, Alt and/or Shift).", but I could find nothing about KeyValue.

Bernard Borg
  • 1,225
  • 1
  • 5
  • 18
  • Finally KeyValue is the raw numeric value. https://social.msdn.microsoft.com/Forums/windows/en-US/384d98e1-9c0c-40ab-9223-b3f0802693f0/keycode-keydata-keyvalue-whats-the-difference?forum=winforms – Leszek P Nov 17 '20 at 13:47
  • Basically never, it is only useful if the keyboard has a key that isn't covered by the Keys enum. Which is technically possible, OEMs may add their own keys to their layout to "add value". But not something you'd like to take advantage of when you want your program to work on any machine. Always favor KeyData first, the modifier key state matters. – Hans Passant Nov 17 '20 at 15:28
  • It might be useful while debugging, the Keys.ToString() method is feeble. – Hans Passant Nov 17 '20 at 15:30

1 Answers1

0

KeyValue is an property of KeyEventArgs.

It is the integer representation of the KeyCode property.

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.keyeventargs.keyvalue?view=net-5.0

It should be on the first page when you google for: c# KeyValue

When would you use it?
Pretty rarely I would say. It could be somewhat easier to store in a database instead of an enum value.

fuchs777
  • 993
  • 1
  • 14
  • 30