WIP - Remote Keyboard

2012-03-18 by

This uses quite a bit of different technologies to present a user with a keyboard from a remote device that will activate a computer monitor.  Kind of like using a network connected device to control a computer like VNC or  Remote desktop, but allowing full API interaction with the actual monitor using Windows Communication Foundation and Services for Windows Mobile Device and any other device that can connect to a LAN.



This uses quite a bit of different technologies to present a user with a keyboard from a remote device that will activate a computer monitor.  Kind of like using a network connected device to control a computer like VNC or  Remote desktop, but allowing full API interaction with the actual monitor using Windows Communication Foundation and  Services for a Windows Mobile Device and any other device that can connect to a LAN.

Here is some code I ahve been using to connect and control the screen through the Windows API and Windows Communication Foundation (WCF)

using System;

using System.Runtime.InteropServices;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace RemoteKeyboard.VK

{

    class API

    {

        [DllImport("user32.dll")]

        internal static extern IntPtr GetMessageExtraInfo();

 

        // For Windows Mobile, replace user32.dll with coredll.dll

        [DllImport("user32.dll", SetLastError = true)]

        internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

 

        // For Windows Mobile, replace user32.dll with coredll.dll

        [DllImport("user32.dll")]

        [return: MarshalAs(UnmanagedType.Bool)]

        internal static extern bool SetForegroundWindow(IntPtr hWnd);

 

 

        [DllImport("user32.dll")]

        internal static extern IntPtr SetFocus(IntPtr hWnd);

 

        [DllImport("user32.dll", SetLastError = true)]

        internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);

    }

}

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace RemoteKeyboard.VK

{

    public class constants

    {

        public const int INPUT_MOUSE = 0;

        public const int INPUT_KEYBOARD = 1;

        public const int INPUT_HARDWARE = 2;

        public const uint KEYEVENTF_EXTENDEDKEY = 0x0001;

        public const uint KEYEVENTF_KEYUP = 0x0002;

        public const uint KEYEVENTF_UNICODE = 0x0004;

        public const uint KEYEVENTF_SCANCODE = 0x0008;

        public const uint XBUTTON1 = 0x0001;

        public const uint XBUTTON2 = 0x0002;

        public const uint MOUSEEVENTF_MOVE = 0x0001;

        public const uint MOUSEEVENTF_LEFTDOWN = 0x0002;

        public const uint MOUSEEVENTF_LEFTUP = 0x0004;

        public const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;

        public const uint MOUSEEVENTF_RIGHTUP = 0x0010;

        public const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020;

        public const uint MOUSEEVENTF_MIDDLEUP = 0x0040;

        public const uint MOUSEEVENTF_XDOWN = 0x0080;

        public const uint MOUSEEVENTF_XUP = 0x0100;

        public const uint MOUSEEVENTF_WHEEL = 0x0800;

        public const uint MOUSEEVENTF_VIRTUALDESK = 0x4000;

        public const uint MOUSEEVENTF_ABSOLUTE = 0x8000;

    }

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

 

namespace RemoteKeyboard.VK

{

    [DataContract]

    public enum VirtualKeys : ushort

    {

        //

        // Virtual Keys, Standard Set

        //

        LBUTTON = 0x01,

        RBUTTON = 0x02,

        CANCEL = 0x03,

        MBUTTON = 0x04,    // NOT contiguous with L & RBUTTON

 

        XBUTTON1 = 0x05,    // NOT contiguous with L & RBUTTON

        XBUTTON2 = 0x06,    // NOT contiguous with L & RBUTTON

 

        // 0x07 : unassigned

 

        BACK = 0x08,

        TAB = 0x09,

 

        // 0x0A - 0x0B : reserved

 

        CLEAR = 0x0C,

        RETURN = 0x0D,

 

        SHIFT = 0x10,

        CONTROL = 0x11,

        MENU = 0x12,

        PAUSE = 0x13,

        CAPITAL = 0x14,

 

        KANA = 0x15,

        HANGEUL = 0x15,  // old name - should be here for compatibility

        HANGUL = 0x15,

        JUNJA = 0x17,

        FINAL = 0x18,

        HANJA = 0x19,

        KANJI = 0x19,

 

        ESCAPE = 0x1B,

 

        CONVERT = 0x1C,

        NONCONVERT = 0x1D,

        ACCEPT = 0x1E,

        MODECHANGE = 0x1F,

 

        SPACE = 0x20,

        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,

 

        //

        // 0 - 9 are the same as ASCII '0' - '9' (0x30 - 0x39)

        // 0x40 : unassigned

        // A - Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)

        //

 

        LWIN = 0x5B,

        RWIN = 0x5C,

        APPS = 0x5D,

 

        //

        // 0x5E : reserved

        //

 

        SLEEP = 0x5F,

 

        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,

        F13 = 0x7C,

        F14 = 0x7D,

        F15 = 0x7E,

        F16 = 0x7F,

        F17 = 0x80,

        F18 = 0x81,

        F19 = 0x82,

        F20 = 0x83,

        F21 = 0x84,

        F22 = 0x85,

        F23 = 0x86,

        F24 = 0x87,

 

        //

        // 0x88 - 0x8F : unassigned

        //

 

        NUMLOCK = 0x90,

        SCROLL = 0x91,

 

        //

        // L* & R* - left and right Alt, Ctrl and Shift virtual keys.

        // Used only as parameters to GetAsyncKeyState() and GetKeyState().

        // No other API or message will distinguish left and right keys in this way.

        //

        LSHIFT = 0xA0,

        RSHIFT = 0xA1,

        LCONTROL = 0xA2,

        RCONTROL = 0xA3,

        LMENU = 0xA4,

        RMENU = 0xA5,

 

        BROWSER_BACK = 0xA6,

        BROWSER_FORWARD = 0xA7,

        BROWSER_REFRESH = 0xA8,

        BROWSER_STOP = 0xA9,

        BROWSER_SEARCH = 0xAA,

        BROWSER_FAVORITES = 0xAB,

        BROWSER_HOME = 0xAC,

 

        VOLUME_MUTE = 0xAD,

        VOLUME_DOWN = 0xAE,

        VOLUME_UP = 0xAF,

        MEDIA_NEXT_TRACK = 0xB0,

        MEDIA_PREV_TRACK = 0xB1,

        MEDIA_STOP = 0xB2,

        MEDIA_PLAY_PAUSE = 0xB3,

        LAUNCH_MAIL = 0xB4,

        LAUNCH_MEDIA_SELECT = 0xB5,

        LAUNCH_APP1 = 0xB6,

        LAUNCH_APP2 = 0xB7,

 

        //

        // 0xB8 - 0xB9 : reserved

        //

 

        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

 

        //

        // 0xC1 - 0xD7 : reserved

        //

 

        //

        // 0xD8 - 0xDA : unassigned

        //

 

        OEM_4 = 0xDB,  //  '[{' for US

        OEM_5 = 0xDC,  //  '\|' for US

        OEM_6 = 0xDD,  //  ']}' for US

        OEM_7 = 0xDE,  //  ''"' for US

        OEM_8 = 0xDF

 

        //

        // 0xE0 : reserved

        //

    }

}

using System;

using System.Runtime.InteropServices;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace RemoteKeyboard.VK

{

    struct MOUSEINPUT

    {

        public int dx;

        public int dy;

        public uint mouseData;

        public uint dwFlags;

        public uint time;

        public IntPtr dwExtraInfo;

    }

 

    struct KEYBDINPUT

    {

        public ushort wVk;

        public ushort wScan;

        public uint dwFlags;

        public uint time;

        public IntPtr dwExtraInfo;

    }

 

    struct HARDWAREINPUT

    {

        public uint uMsg;

        public ushort wParamL;

        public ushort wParamH;

    }

 

    [StructLayout(LayoutKind.Explicit)]

    struct MOUSEKEYBDHARDWAREINPUT

    {

        [FieldOffset(0)]

        public MOUSEINPUT mi;

 

        [FieldOffset(0)]

        public KEYBDINPUT ki;

 

        [FieldOffset(0)]

        public HARDWAREINPUT hi;

    }

 

    struct INPUT

    {

        public int type;

        public MOUSEKEYBDHARDWAREINPUT mkhi;

    }

}

 

This code allows for the use of the use of the Windows API to  change the screen .  I am still working n adding to a Windows Service that should be completed soon.

 

This is a work in progress so please tell me if you are interested.  I can probably help you solve some issues with Remote LAN devices and remote computers.