[ create a new paste ] login | about

Link: http://codepad.org/njpdHzsU    [ raw code | output | fork ]

C, pasted on Apr 24:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ConsoleApp1
{
    class Program
    {
        private const int WH_KEYBOARD_LL = 13;
        private const int WM_KEYDOWN = 0x0100;
        private const int WM_KEYUP = 0x0101;
        private static string notepadPath = null;
        private static LowLevelKeyboardProc _proc = HookCallback;
        private static IntPtr _hookID = IntPtr.Zero;
        private static int keycodeold = 0;

        private delegate IntPtr LowLevelKeyboardProc(
            int nCode, IntPtr wParam, IntPtr lParam);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr GetModuleHandle(string lpModuleName);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SetWindowsHookEx(int idHook,
            LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool UnhookWindowsHookEx(IntPtr hhk);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
            IntPtr wParam, IntPtr lParam);

        public static void Start(string _notepadPath)
        {
            notepadPath = _notepadPath;
            _hookID = SetHook(_proc);
            Application.Run();
            UnhookWindowsHookEx(_hookID);
        }

        private static IntPtr SetHook(LowLevelKeyboardProc proc)
        {
            using (Process curProcess = Process.GetCurrentProcess())
            using (ProcessModule curModule = curProcess.MainModule)
            {
                return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
                    GetModuleHandle(curModule.ModuleName), 0);
            }
        }

        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            int vkCode = Marshal.ReadInt32(lParam);
            var keyName = Enum.GetName(typeof(Keys), vkCode);
            Console.WriteLine(keyName + "\t" + vkCode);
            if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN && keycodeold == 162 && vkCode == 192)
            {

                SendKeys.Send("{1}");
            }

            /*
            if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
            {

                if((vkCode>=49 && vkCode <= 55))
                {
                    SendKeys.Send("{0}");
                    SendKeys.Send("{9}");
                    SendKeys.Send("{8}");
                    
                }

            }
            if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP)
            {
               

                if ((vkCode >= 112 && vkCode <= 115))
                {
                    SendKeys.Send("{0}");
                    SendKeys.Send("{9}");
                    SendKeys.Send("{8}");
                    Console.WriteLine(keyName);
                }


            }*/

            keycodeold = vkCode;

            return CallNextHookEx(_hookID, nCode, wParam, lParam);
        }


        static void Main(string[] args)
        {

            Program.Start("");
        }
    }
}


Output:
1
2
3
4
5
6
7
8
9
10
Line 1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 2: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 4: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 5: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 6: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 8: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'System'
Line 11: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ConsoleApp1'


Create a new paste based on this one


Comments: