I'm making a Windows application that captures keyboard input globally. When a user uses the CTRL + ALT + G shortcut combo the application uses
SendKey.Send(Guid.NewGuid().ToString());
to type a generaged GUID into whatever text field is in focus. And it should do this regardless of the application taking the input.
It works exactly as I intended the first time you type CTRL + ALT + G but subsequent attempts result in nothing, or just very infrequent successes.
I mean, it all should be very simple and consistent. I have a working global keyboard hook which works all the time, I've tested it, but the SendKey.Send() method doesn't work every time.
I've looked all over Google at anything related to my issue but nothing has worked so far.
Anyone have any insight?
EDIT 1: I've tried using SendKey.SendWait() as well, does the same thing. I really want a more responsive way to generate new GUID using this keyboard shortcut approach.
EDIT 2:
Below is the essential parts of the code:
/* Initialization Code Here */
// register the event that is fired after the key press.
hook.KeyPressed += new EventHandler<KeyPressedEventArgs>(hook_KeyPressed);
// register the control + alt + F12 combination as hot key.
hook.RegisterHotKey((uint)(HotkeyModifiers.Control | HotkeyModifiers.Alt), Keys.G);
The event code is quite simple:
void hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
SendKeys.SendWait(Guid.NewGuid().ToString());
}
Everything else in my project is just fluff.
Update 1:
I do have more questions about this subject, but I am out of time to continue working on this for today. I have implemented Jon Raynor's suggestion of using the app.config approach to some degree of success. Once I isolate my new problems I'll post an edit and possibly close this question if I get my application functioning as intended.