I can't find anything on this with a Google search, I can only find things about telling the user what button they pressed. What I'm looking to do is I want to use the users' numpad to navigate a menu. So if they press 8 on the numpad, I want it to go up a button. If they press 5 on the numpad, I want it to open the highlighted button. If they press 2 on the numpad, I want it to go down a button. Normally this would be the point where a user would give code to what they're doing currently and asking why it isn't working, but I can't figure anything out about this. All I know is that is has something to do with registering a KeyPress, KeyUp, or KeyDown event with the key codes for the numpad (i.e. numpad 8 = 104.) If I could get any help that would be great, thanks!
Asked
Active
Viewed 138 times
0
-
1Helps if you tell us the platform: WinForms, WPF, Web, etc? Edit your tags appropriately. – LarsTech Jul 02 '20 at 00:11
-
you are right: you need to register the keyboard event somewhere. Your buttons will need to know their index in the array and depending on the key you add or subtract one from the currentIndex. – Richard Barker Jul 02 '20 at 00:15
-
@LarsTech I'm using Visual Studio, but I can't add that as a tag because the visual studio tag isn't for the programming language associated with it. – Bizzie Jul 02 '20 at 00:19
-
What controls are you referring to when you say *buttons in a menu*? Menu items or standard Buttons used as selectors, not related to a Menu? Something like [this](https://stackoverflow.com/a/59666527/7444103)? – Jimi Jul 02 '20 at 00:20
-
@Jimi yes, something like what you linked. The buttons would be standard buttons, I was just referring to the GUI as a menu for clarification. – Bizzie Jul 02 '20 at 00:34
-
Well, do it like that then. The only difference, using the Numeric Pad, is that when `Num Lock` is active, you have to also handle `Keys.NumPad4` and `Keys.NumPad6`. When `Num Lock` is not active, it works the same way (i.e., you just need to handle `Keys.Up` and `Keys.Down`, as shown in that example). – Jimi Jul 02 '20 at 00:55
-
I've updated that code to also work with a Numeric Pad, active or inactive. – Jimi Jul 02 '20 at 01:28
-
Given that the user can turn off NumLock and then the number pad keys work as arrows anyway, is this even required? – jmcilhinney Jul 02 '20 at 01:39
-
@jmcilhinney Yes, for example in cashier apps to select items. (1) Coffee (2) Tea (3) Beer ...etc. So, pick a number please. – Jul 02 '20 at 06:21
-
1@JQSOFT, that's not what's being asked for here though. In this case the request is for 8 and 2 to go up and down respectively, which is exactly what they do with NumLock off. The request is also for 5 to act like the Enter key but, given that you have an Enter key on the keypad, this seems a bit unnecessary to me. If the specific functionality described is what's desired then that's fine but it seems to be solving a problem that doesn't exist. – jmcilhinney Jul 02 '20 at 06:39