I've seen countless of posts and articles claiming to do what I expect them to do for me, sadly none of them has granted me a solution or helped me so far.
You see, I'm using: https://github.com/gmamaladze/globalmousekeyhook as a Keyboard Hook...
Now as the Usage explains on GlobalHookKeyPress Event, I'm trying to implement:
if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { textBlock.Text = string.Format("CTRL + {0}", e.KeyChar); }
To capture CTRL + <'Put Captured KeyCode Here'> (e.g. CTRL + A), however, when I do it that way, it simply writes "CTRL +" to the textBlock, and not the captured Key... Now if I try to do instead:
int key = Convert.ToInt32(e.KeyChar); if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { textBlock.Text = string.Format("CTRL + {0}", key); }
it properly writes the CTRL + "KeyCode" however, it gives me the right one but in its "numerical" form, now, what I would have to do in order to make it "CTRL + A", and not, "CTRL + 1"?
I have tried one way but it seemed over-complicated and probably useless as there could be better ways to implement what I'm looking for, This is what I did:
int key = Convert.ToInt32(e.KeyChar);
if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
{
switch (key)
{
case 1:
textBlock.Text = "CTRL + A";
break;
...
default:
break;
}
}
Now, my idea is to where you see the ... to obviously keep on writing (case 19 for "CTRL + S" and so on...) but as you can see, it will end up being too tedious for the task... What you would recommend to do for this special case.
UPDATE #1
Ok so I kept digging and this made it work, I don't know how, but it just did it
Now I'm running into a little issue... In order to register the keypress, I have to press the target key twice... or even press another key then come back to the target key and then it will register, like some sort of delay, Let me explain myself...
I want to press CTRL + A I hit CTRL + A, and it doesn't do anything, however if I press CTRL + B, it seems it hasn't done anything and it just displays nothing, however if I do press CTRL + B then back to CTRL + A, it properly displays CTRL + A, hope you understand me... Now I don't know what is happening, but I'm digging through, if you happen to know, please share it with me, it will be really helpful :D
Cheers!