Example #1
0
 public Form1()
 {
     InitializeComponent();
       rawInput = new RawInput(Handle);
       rawInput.AddMessageFilter();
       rawInput.Keyboard.DevicesChanged += Keyboards_DevicesChanged;
       rawInput.Keyboard.EnumerateDevices();
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyboardInputEventArgs"/> class.
 /// </summary>
 /// <param name="rawInput">The raw input.</param>
 internal KeyboardInputEventArgs(ref RawInput rawInput)
     : base(ref rawInput)
 {
     Key = (Keys) rawInput.Data.Keyboard.VKey;
     MakeCode = rawInput.Data.Keyboard.MakeCode;
     ScanCodeFlags = rawInput.Data.Keyboard.Flags;
     State = rawInput.Data.Keyboard.Message;
     ExtraInformation = rawInput.Data.Keyboard.ExtraInformation;
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HidInputEventArgs"/> class.
 /// </summary>
 /// <param name="rawInput">The raw input.</param>
 /// <param name="hwnd">The handle of the window that received the RawInput mesage.</param>
 internal HidInputEventArgs(ref RawInput rawInput, IntPtr hwnd) : base(ref rawInput, hwnd)
 {
     Count = rawInput.Data.Hid.Count;
     DataSize = rawInput.Data.Hid.SizeHid;
     RawData = new byte[Count * DataSize];
     unsafe
     {
         if (RawData.Length > 0) fixed (void* __to = RawData) fixed (void* __from = &rawInput.Data.Hid.RawData) SharpDX.Utilities.CopyMemory((IntPtr)__to, (IntPtr)__from, RawData.Length *sizeof(byte));
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MouseInputEventArgs"/> class.
 /// </summary>
 /// <param name="rawInput">The raw input.</param>
 internal MouseInputEventArgs(ref RawInput rawInput)
     : base(ref rawInput)
 {
     Mode = (MouseMode) rawInput.Data.Mouse.Flags;
     ButtonFlags = (MouseButtonFlags)rawInput.Data.Mouse.ButtonsData.ButtonFlags;
     WheelDelta = rawInput.Data.Mouse.ButtonsData.ButtonData;
     Buttons = rawInput.Data.Mouse.RawButtons;
     X = rawInput.Data.Mouse.LastX;
     Y = rawInput.Data.Mouse.LastY;
     ExtraInformation = rawInput.Data.Mouse.ExtraInformation;
 }
 public static extern bool RegisterRawInputDevices(RawInput.RawInputDevice[] pRawInputDevice, uint numberDevices, uint size);
 public static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, IntPtr notificationFilter, RawInput.DeviceNotification flags);
 public static extern uint GetRawInputDeviceInfo(IntPtr hDevice, uint command, ref RawInput.DeviceInfo data, ref uint dataSize);
 public static extern uint GetRawInputDeviceInfo(IntPtr hDevice, RawInput.RawInputDeviceInfo command, IntPtr pData, ref uint size);
 public static extern int GetRawInputData(IntPtr hRawInput, RawInput.DataCommand command, [Out] IntPtr pData, [In, Out] ref int size, int sizeHeader);
Example #10
0
 public static extern int GetRawInputData(IntPtr hRawInput, RawInput.DataCommand command, [Out] out RawInput.RawInputData buffer, [In, Out] ref int size, int cbSizeHeader);
Example #11
0
        private void InitializationSniffer(bool iscmd = false)
        {
            this.Visible = false;

            if (!iscmd) AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
            input = new RawInput(Handle);
            if (!iscmd) input.AddMessageFilter();                   // Adding a message filter will cause keypresses to be handled
            if (!iscmd) input.KeyPressed += OnKeyPressed;

            this.CollectionHidDeviceInfo = input.CollectionHidDeviceInfo;

            if (!iscmd) notifyIcon1.Icon = (System.Drawing.Icon)resources.GetObject("Connected");
            if (!iscmd) notifyIcon1.ShowBalloonTip(1, "Connected", "Start scanning.", ToolTipIcon.Info);
        }
Example #12
0
 private void exitToolStripMenuItem_Click(object sender, EventArgs e)
 {
     isstopped = true;
     input = null;
     Application.Exit();
 }
Example #13
0
 internal RawInputEventArgs(ref RawInput rawInput)
 {
     Device = rawInput.Header.Device;
 }
Example #14
0
        internal RawInputEventArgs(ref RawInput rawInput, IntPtr hwnd)
        {
            Device = rawInput.Header.Device;
	        WindowHandle = hwnd;
        }
		/// <summary>Performs a buffered read of the raw input data.</summary>
		/// <returns></returns>
		/// <exception cref="Win32Exception"/>
		internal static RawInput[] GetRawInputBuffer()
		{
			var headerSize = Marshal.SizeOf( typeof( RawInputHeader ) );
			var size = 0;
			
			var result = GetRawInputBuffer( null, ref size, headerSize );
			if( result == -1 )
				throw new Win32Exception( "Failed to retrieve raw input buffer size.", GetExceptionForLastWin32Error() );

			var count = size / Marshal.SizeOf( typeof( RawInput ) );
			var buffer = new RawInput[ count ];
			
			result = GetRawInputBuffer( buffer, ref size, headerSize );
			if( result == -1 )
				throw new Win32Exception( "Failed to retrieve raw input buffer.", GetExceptionForLastWin32Error() );

			return buffer;
		}
		//UINT WINAPI GetRawInputData(
		//  _In_      HRAWINPUT hRawInput,
		//  _In_      UINT      uiCommand,
		//  _Out_opt_ LPVOID    pData,
		//  _Inout_   PUINT     pcbSize,
		//  _In_      UINT      cbSizeHeader
		//);


		/// <summary>Returns the raw input from the specified device.</summary>
		/// <param name="rawInputHandle">A handle to the <see cref="RawInput"/> structure. This comes from the LParam in WM_INPUT.</param>
		/// <param name="rawInput"></param>
		/// <exception cref="Win32Exception"/>
		/// <exception cref="InvalidDataException"/>
		internal static void GetRawInputData( IntPtr rawInputHandle, out RawInput rawInput )
		{
			var headerSize = Marshal.SizeOf( typeof( RawInputHeader ) );
			var size = Marshal.SizeOf( typeof( RawInput ) );

			var result = GetRawInputData( rawInputHandle, GetDataCommand.Input, out rawInput, ref size, headerSize );
			if( result == -1 )
				throw new Win32Exception( "Failed to retrieve raw input data.", GetExceptionForLastWin32Error() );
		}