0

I am wanting to create a simple application that when running would wait for a specific key or combination of keys OR even button presses on a mouse. I am using the MouseKeyHook API in order to get this information, however I am running into a few issues.

This seems to work perfectly, as I can compare the string values of the Buttons with what I have saved. Now here is where the real issue begins. Whenever I press any programmable button on my keyboard I dont get ANY output? Why?

private void GlobalHookKeyPress(object sender, KeyPressEventArgs e)
{
    HotKey.Text = e.KeyChar.ToString();
}

private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
{
    HotKey.Text = e.Button.ToString();
}

When Hooking using the MouseKeyHook API, I was able to get the two mouse buttons XButton1 and XButton2 but I got nothing for my keyboard buttons.

enter image description here

Hunter Mitchell
  • 7,063
  • 18
  • 69
  • 116
  • 1
    Programmable keys tend to use specific APIs that require manufacturer driver software. – DavidG Nov 23 '15 at 00:55
  • @DavidG Sounds about right, but how can most Games detect these buttons and allow use of them and I cant without Driver software? – Hunter Mitchell Nov 23 '15 at 00:58
  • @FeaRCODE I could be wrong, but the only programmable buttons that I've seen working were mapped to various keyboard key combinations in the mouse driver. – xxbbcc Nov 23 '15 at 01:00
  • Have you set up macros in your driver software for these buttons? Usually you set button X to perform action Y where Y could be a number of keypresses, you should be able to pick up those mapped actions. – DavidG Nov 23 '15 at 01:01
  • @DavidG Actually I have not. And I just tested this in a game. My mouse buttons were recognized in the Game, however my buttons on the keyboard were not. – Hunter Mitchell Nov 23 '15 at 01:03
  • @xxbbcc I think you are actually correct. If you look at my answer to David's comment. – Hunter Mitchell Nov 23 '15 at 01:03
  • If this is the case though, how can the Mouse Buttons be working? And be Shown as `XButton1` and `XButton2`? – Hunter Mitchell Nov 23 '15 at 01:07
  • 1
    Mouse buttons are pretty generic, the windows API allows for 8 buttons. Any more than that requires specific vendor drivers. – DavidG Nov 23 '15 at 01:08
  • Thank you @DavidG, If you would, post an answer describing what you told me. It would help others that have the same issue. – Hunter Mitchell Nov 23 '15 at 01:09

1 Answers1

0

Programmable keys on keyboard tend to use specific APIs that require vendor driver software. That software maps a key press to an action (or sequence of actions) that translate to standard operations. For example, press button X could correspond to pressing the A key five times in a row and your software should be able to pick up those 5 presses.

Mouse buttons are pretty generic and I believe the windows API allows for 8 standard buttons (see the API reference here). Any more than that requires specific vendor drivers again and for those buttons to be mapped.

DavidG
  • 113,891
  • 12
  • 217
  • 223