View difference between Paste ID: f6Rg1cNQ and jWr8h5jC
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Windows.Forms;
3
using System.Runtime.InteropServices;
4
5
namespace WoWChat
6
{
7
    class WoWSlashCommand
8
    {
9
10
        [DllImport("user32.dll")]
11
        private static extern int SendMessage(IntPtr thWnd, int msg, int wParam, IntPtr lParam);
12
13
        private const int VK_CONTROL = 0xA2;
14
        private const int WM_KEYDOWN = 0x100;
15
        private const int WM_KEYUP = 0x101;
16
        private const int VK_RETURN = 0x0D;
17
18
        public static void send(IntPtr hWnd, string slashCommand)
19
        {
20
            Object savedClipboard = Clipboard.GetDataObject();
21
            Clipboard.SetText(slashCommand);
22
23
            SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, IntPtr.Zero);
24
            SendMessage(hWnd, WM_KEYUP, VK_RETURN, IntPtr.Zero);
25
26
            SendMessage(hWnd, WM_KEYDOWN, VK_CONTROL, IntPtr.Zero);
27
            SendMessage(hWnd, WM_KEYDOWN, 0x56, IntPtr.Zero);
28
            SendMessage(hWnd, WM_KEYUP, 0x56, IntPtr.Zero);
29
            SendMessage(hWnd, WM_KEYUP, VK_CONTROL, IntPtr.Zero);
30
31
            SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, IntPtr.Zero);
32
            SendMessage(hWnd, WM_KEYUP, VK_RETURN, IntPtr.Zero);
33
34
            Clipboard.SetDataObject(savedClipboard);
35
        }
36
    }
37
}