My C # program has very strange behavior. I use four pinvoke methods in this program: GlobalKeyHooking, HotKey Registering, SetForegroundWindow / GetForegroundWindow and SendKeys.Send / SendWait.
This is where there is behavior that I do not understand. I steal Ctrl + V in a program where the standard cut / copy & paste procedure is replaced with an autocomplete list in the list that appears and disappears. On some computers with Windows 7, my programs work like a charm, on other 50% of computers with Windows 7 (and, unfortunately, there is no VS2010 for debugging it), a very strange cycle appears --- inside --- method. Since Ctrl and V are themselves connected, I already prevented the method from running endlessly. This is normal. But another cycle appears inside the method.
In short: myDebugValue increases to 23-24-25! So something tries to execute the function many times before deciding to stop.
Has anyone already seen a similar unwanted cycle? Despite the lack of a try / catch block, it bounces inside the function.
Could some P / Invokes bug on some Windows 7 and not others?
Are P / Invokes own invisible low-level try / catch assembler error handlers stronger than running my C # program?
Visually, when I do this, I see that my program interface flashes quickly many times, 25 times, I think.
private bool getOutOfHere = false; private int myDebugValue = 0; private void globalKeyHooking_KeyUp(object sender, KeyEventArgs e) { if (getOutOfHere) return; myDebugValue = 0; if (e.KeyCode == Keys.LControlKey) { getOutOfHere = true; SendKeys.SendWait("^v"); getOutOfHere = false; myDebugValue++; } }
I tried to compile with 2.0, 3.0 and 4.0 and on the same 4 computers, in all cases, this is still the same indicator: 50% of failures, 50% works.
[change]
I really think that SendKeys.Send works differently on different computers with Windows 7.