keybd_event kaldes 2 gange, een gang for "tryk" og een gang for "slip". Se mine msdn links for "specielle" taster som "tab" scroll lock osvosvo..
hvis du har brug for at læse en tasts tilstand skal du bruge et andet API kald, tror det hedder noget med GetKeyState, eller noget "logisk" i den stil ;)
se evt. www.pinvoke.net, hvis du vil bruge SendInput istedet for ... skriv evt. hvis du skal ha' lidt hjælp til at komme igang med den... den kræver lidt mere kode.
Det lykkedes mig med sendInput. Lavede en klasse selv, kan lige så godt smide den her til glæde for andre......
using System; using System.Runtime.InteropServices; using System.Windows.Forms;
namespace MOUSEMOVE { /// <summary> /// Summary description for Keyboard. /// </summary> public class KeyboardApi {
public KeyboardApi() { // // TODO: Add constructor logic here // } [DllImport("user32.dll")] static extern uint SendInput(uint nInputs, INPUT [] pInputs, int cbSize); [StructLayout(LayoutKind.Explicit)] struct INPUT { [FieldOffset(0)] public int type; [FieldOffset(4)] MOUSEINPUT mi; [FieldOffset(4)] public KEYBDINPUT ki; [FieldOffset(4)] HARDWAREINPUT hi; } [StructLayout(LayoutKind.Sequential)] struct MOUSEINPUT { int dx; int dy; int mouseData; int dwFlags; int time; IntPtr dwExtraInfo; }
[StructLayout(LayoutKind.Sequential)] struct KEYBDINPUT { public short wVk; public short wScan; public int dwFlags; public int time; public IntPtr dwExtraInfo; }
[StructLayout(LayoutKind.Sequential)] struct HARDWAREINPUT { int uMsg; short wParamL; short wParamH; }
uint ret = SendInput((uint)inputs.Length,inputs,Marshal.SizeOf(inputs[0])); if ( ret != (uint)inputs.Length) throw new ApplicationException("SendInput error: " + Marshal.GetLastWin32Error().ToString());
Console.WriteLine("ok...."); }
public enum VK : short { SHIFT = 0x10, CONTROL = 0x11, MENU = 0x12, ESCAPE = 0x1B, BACK = 0x08, TAB = 0x09, RETURN = 0x0D, PRIOR = 0x21, NEXT = 0x22, END = 0x23, HOME = 0x24, LEFT = 0x25, UP = 0x26, RIGHT = 0x27, DOWN = 0x28, SELECT = 0x29, PRINT = 0x2A, EXECUTE = 0x2B, SNAPSHOT = 0x2C, INSERT = 0x2D, DELETE = 0x2E, HELP = 0x2F, NUMPAD0 = 0x60, NUMPAD1 = 0x61, NUMPAD2 = 0x62, NUMPAD3 = 0x63, NUMPAD4 = 0x64, NUMPAD5 = 0x65, NUMPAD6 = 0x66, NUMPAD7 = 0x67, NUMPAD8 = 0x68, NUMPAD9 = 0x69, MULTIPLY = 0x6A, ADD = 0x6B, SEPARATOR = 0x6C, SUBTRACT = 0x6D, DECIMAL = 0x6E, DIVIDE = 0x6F, F1 = 0x70, F2 = 0x71, F3 = 0x72, F4 = 0x73, F5 = 0x74, F6 = 0x75, F7 = 0x76, F8 = 0x77, F9 = 0x78, F10 = 0x79, F11 = 0x7A, F12 = 0x7B, OEM_1 = 0xBA, // ',:' for US OEM_PLUS = 0xBB, // '+' any country OEM_COMMA = 0xBC, // ',' any country OEM_MINUS = 0xBD, // '-' any country OEM_PERIOD = 0xBE, // '.' any country OEM_2 = 0xBF, // '/?' for US OEM_3 = 0xC0, // '`~' for US MEDIA_NEXT_TRACK = 0xB0, MEDIA_PREV_TRACK = 0xB1, MEDIA_STOP = 0xB2, MEDIA_PLAY_PAUSE = 0xB3, LWIN =0x5B, RWIN =0x5C }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.