keys
-
please help me. how do i simulate a key/key combination press. let's say when an event is trigerred, i want the form to act like i presse the escape key, or alt+f4!
rzvme
-
You can use the SendInput() function from the native win32, here is an example how to do it: http://www.cornetdesign.com/2005/04/screen-print-capture-in-c-using_08.html[^] - Pawel
i had a look at the cide in the web site and i think i got it but i dont understand 2 things: 1) the alt key isn't in your enum VK 2) your call to the send input method (NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); etc.) where is the alt key or print screen key in your function call? What would change in the code if , for example, i would want to pres ctrl+g instead of alt+print screen cheers!
rzvme
-
You can use the SendInput() function from the native win32, here is an example how to do it: http://www.cornetdesign.com/2005/04/screen-print-capture-in-c-using_08.html[^] - Pawel
i added a few code lines to press enter before and escape after pressing ctrl+g .right now my code looks like this. The ctrl+g part of the code works fine, but the rest doesn't work at all. what's wrong? // to press enter structInput.ki.wVk = (ushort)NativeWIN32.VK.RETURN; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // Key up the actual key-code structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)NativeWIN32.VK.RETURN;//vk; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); //Press control Key structInput.ki.wVk = (ushort)NativeWIN32.VK.CONTROL; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // Key down the actual key-code structInput.ki.wVk = (ushort)NativeWIN32.VK.G;//vk; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // Key up the actual key-code structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)NativeWIN32.VK.G;//vk; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); //Keyup control structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)NativeWIN32.VK.CONTROL; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // to press escape structInput.ki.wVk = (ushort)NativeWIN32.VK.ESCAPE; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); // Key up the actual key-code structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)NativeWIN32.VK.ESCAPE;//vk; intReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput));
rzvme