private HookEventArgs[] DecodeHookEvents(Stream ls) { List <HookEventArgs> hookEvents = new List <HookEventArgs>(); MemoryStream ms = ls as MemoryStream; HookEventCodec.EventClass ec; HookEventCodec.EventType et; HookEventArgs ha; byte[] pressedKeys; char pressedChar; int offset = 0; while (HookEventCodec.GetDecodedData(offset, ms.ToArray(), out ec, out et, out ha, out pressedKeys, out pressedChar)) { if (ec == HookEventCodec.EventClass.MouseEvent) { ha = new MouseHookEventArgsEx(ha as MouseHookEventArgs, et); offset += (int)HookEventCodec.Offsets.MouseLogOffset; } else { KeyHookEventArgs e = ha as KeyHookEventArgs; List <System.Windows.Forms.Keys> pKeys = new List <System.Windows.Forms.Keys>(); foreach (byte b in pressedKeys) { if (b != 0) { pKeys.Add((System.Windows.Forms.Keys)b); } } offset += (int)HookEventCodec.Offsets.KeyLogOffset; ha = new KeyHookEventArgsEx(e, et, pKeys, pressedChar); } hookEvents.Add(ha); } return(hookEvents.ToArray()); }
public void DecodeEvent(int owner, byte[] data) { this._neuroLog.WriteFormat("Decode Event", "Owner: {0}\n\nData:\n{1}", owner, data); HookEventCodec.EventClass ec; HookEventCodec.EventType et; HookEventArgs ea; byte[] _b; char _c; HookEventCodec.GetDecodedData(0, data, out ec, out et, out ea, out _b, out _c); if (ec == HookEventCodec.EventClass.KeyEvent) { KeyHookEventArgs ke = ea as KeyHookEventArgs; switch (et) { case HookEventCodec.EventType.KeyDown: //Log.WriteLine("[KeyDown]->" + ke.KeyCode); this._neuroLog.WriteFormat("Key Down", "Key Code: {0}", ke.KeyCode); this._ki.KeyDown(ke.KeyCode); break; case HookEventCodec.EventType.KeyPress: //Log.WriteLine("[KeyPress]->" + ke.KeyCode); this._neuroLog.WriteFormat("Key Press", "Key Code: {0}", ke.KeyCode); this._ki.KeyPress(ke.KeyCode, ke.Alt, ke.Control, ke.Shift); break; case HookEventCodec.EventType.KeyUp: //Log.WriteLine("[KeyUp]->" + ke.KeyCode); this._neuroLog.WriteFormat("Key Up", "Key Code: {0}", ke.KeyCode); this._ki.KeyUp(ke.KeyCode); break; } } else if (ec == HookEventCodec.EventClass.MouseEvent) { MouseHookEventArgs me = ea as MouseHookEventArgs; KeyHookEventArgs ke = ea as KeyHookEventArgs; switch (et) { case HookEventCodec.EventType.MouseClick: //Log.WriteLine("[Click]"); this._neuroLog.WriteFormat("Mouse Click", "Button: {0}\nCount: {1}", me.Button, me.ClickCount); this._mi.MouseClick(me.Button, me.ClickCount); break; case HookEventCodec.EventType.MouseDoubleClick: //Log.WriteLine("[DoubleClick]"); this._neuroLog.WriteFormat("Mouse Double Click", "Button: {0}", me.Button); this._mi.MouseDoubleClick(me.Button); break; case HookEventCodec.EventType.MouseDown: //Log.WriteLine("[MouseDown]"); this._neuroLog.WriteFormat("Mouse Down", "Button: {0}", me.Button); this._mi.MouseDown(me.Button); break; case HookEventCodec.EventType.MouseMove: //int x = (int)(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width * (me.Location.X / Math.Pow(10, this.NormalizedPrecisionFactor))); //int y = (int)(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height * (me.Location.Y / Math.Pow(10, this.NormalizedPrecisionFactor))); int x = (int)(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width * ((ushort)me.Location.X / 65535.0f)); int y = (int)(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height * ((ushort)me.Location.Y / 65535.0f)); //this._neuroLog.WriteFormat("Mouse Move", "Normalized Location: {0}, {1}\nClient Location: {2}, {3}", me.Location.X, me.Location.Y, x, y); //Log.WriteLine(String.Format("{0} -> {1}, {2} -> {3}", (ushort)me.Location.X, x, (ushort)me.Location.Y, y)); /*using (StreamWriter sw = new StreamWriter("log.txt",true)) * { * sw.WriteLine(String.Format("[{0},{1}] | {2}, {3}", me.Location.X.ToString(), me.Location.Y.ToString(), x.ToString(), y.ToString())); * }*/ this._mi.MouseMove(x, y); break; case HookEventCodec.EventType.MouseUp: //Log.WriteLine("[MouseUp]"); this._neuroLog.WriteFormat("Mouse Up", "Button: {0}", me.Button); this._mi.MouseUp(me.Button); break; case HookEventCodec.EventType.MouseWheel: //Log.WriteLine("[Scroll]"); this._neuroLog.WriteFormat("Mouse Scroll", "Amount: {0}", me.ScrollAmount); this._mi.MouseScroll(me.ScrollAmount); break; } } }