Click here to Skip to main content
15,913,184 members
Home / Discussions / C#
   

C#

 
GeneralRe: windows not in focus Pin
wjp_auhtm17-Jan-10 22:26
wjp_auhtm17-Jan-10 22:26 
GeneralRe: windows not in focus Pin
michaelgr117-Jan-10 22:39
michaelgr117-Jan-10 22:39 
GeneralRe: windows not in focus Pin
wjp_auhtm17-Jan-10 22:57
wjp_auhtm17-Jan-10 22:57 
GeneralRe: windows not in focus Pin
Heinzzy18-Jan-10 3:51
Heinzzy18-Jan-10 3:51 
GeneralRe: windows not in focus Pin
wjp_auhtm18-Jan-10 14:21
wjp_auhtm18-Jan-10 14:21 
GeneralRe: windows not in focus Pin
Ravi Bhavnani17-Jan-10 9:26
professionalRavi Bhavnani17-Jan-10 9:26 
GeneralRe: windows not in focus Pin
wjp_auhtm17-Jan-10 18:41
wjp_auhtm17-Jan-10 18:41 
AnswerRe: windows not in focus Pin
Heinzzy17-Jan-10 5:47
Heinzzy17-Jan-10 5:47 
To capture Keyboard stream use hooks

Read this http://msdn.microsoft.com/en-us/library/ms632589(VS.85).aspx[^]

Simple example
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Diagnostics;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace hook<br />
{<br />
    class Program<br />
    {<br />
        private const int WH_KEYBOARD_LL = 13;<br />
        private const int WM_KEYDOWN = 0x0100;<br />
        private static LowLevelKeyboardProc _proc = HookCallback;<br />
        private static IntPtr _hookID = IntPtr.Zero;<br />
<br />
        static void Main()<br />
        {<br />
            _hookID = SetHook(_proc);<br />
            Application.Run();<br />
            UnhookWindowsHookEx(_hookID);<br />
<br />
        }<br />
<br />
        private static IntPtr SetHook(LowLevelKeyboardProc proc)<br />
        {<br />
            using (Process curProcess = Process.GetCurrentProcess())<br />
            using (ProcessModule curModule = curProcess.MainModule)<br />
            {<br />
                return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);<br />
            }<br />
        }<br />
<br />
        private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);<br />
<br />
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)<br />
        {<br />
            if ((nCode >= 0) && (wParam == (IntPtr)WM_KEYDOWN))<br />
            {<br />
                int vkCode = Marshal.ReadInt32(lParam);<br />
                if (((Keys)vkCode == Keys.LWin) || ((Keys)vkCode == Keys.RWin))<br />
                {<br />
                    Console.WriteLine("{0} blocked!", (Keys)vkCode);<br />
                    return (IntPtr)1;<br />
                }<br />
            }<br />
            return CallNextHookEx(_hookID, nCode, wParam, lParam);<br />
        }<br />
<br />
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]<br />
        private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);<br />
<br />
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]<br />
        private static extern bool UnhookWindowsHookEx(IntPtr hhk);<br />
<br />
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]<br />
        private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);<br />
<br />
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]<br />
        private static extern IntPtr GetModuleHandle(string lpModuleName);<br />
<br />
    <br />
    <br />
    }<br />
}<br />
<br />

GeneralRe: windows not in focus Pin
michaelgr117-Jan-10 6:40
michaelgr117-Jan-10 6:40 
QuestionHow to reject changes between two equal DataTables? Pin
obarahmeh16-Jan-10 21:13
obarahmeh16-Jan-10 21:13 
AnswerRe: How to reject changes between two equal DataTables? Pin
dan!sh 16-Jan-10 21:20
professional dan!sh 16-Jan-10 21:20 
QuestionUSB read Pin
michaelgr116-Jan-10 20:39
michaelgr116-Jan-10 20:39 
AnswerRe: USB read Pin
Alex Manolescu16-Jan-10 21:24
Alex Manolescu16-Jan-10 21:24 
QuestionMicrosoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server ‘\\.\pipe\3F103E6E-3FD4-47\tsql\query’ Pin
Mohammad Dayyan16-Jan-10 20:28
Mohammad Dayyan16-Jan-10 20:28 
AnswerRe: Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server ‘\\.\pipe\3F103E6E-3FD4-47\tsql\query’ Pin
dan!sh 16-Jan-10 21:15
professional dan!sh 16-Jan-10 21:15 
GeneralRe: Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server ‘\\.\pipe\3F103E6E-3FD4-47\tsql\query’ Pin
Mohammad Dayyan16-Jan-10 21:21
Mohammad Dayyan16-Jan-10 21:21 
GeneralRe: Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server ‘\\.\pipe\3F103E6E-3FD4-47\tsql\query’ Pin
dan!sh 16-Jan-10 21:54
professional dan!sh 16-Jan-10 21:54 
GeneralRe: Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server ‘\\.\pipe\3F103E6E-3FD4-47\tsql\query’ Pin
Mohammad Dayyan16-Jan-10 23:29
Mohammad Dayyan16-Jan-10 23:29 
GeneralRe: Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server ‘\\.\pipe\3F103E6E-3FD4-47\tsql\query’ Pin
dan!sh 16-Jan-10 23:57
professional dan!sh 16-Jan-10 23:57 
GeneralRe: Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server ‘\\.\pipe\3F103E6E-3FD4-47\tsql\query’ Pin
Mohammad Dayyan17-Jan-10 0:20
Mohammad Dayyan17-Jan-10 0:20 
Questionwriting a windows service Pin
benams16-Jan-10 20:26
benams16-Jan-10 20:26 
AnswerRe: writing a windows service Pin
dan!sh 16-Jan-10 20:59
professional dan!sh 16-Jan-10 20:59 
GeneralRe: writing a windows service Pin
#realJSOP17-Jan-10 3:25
professional#realJSOP17-Jan-10 3:25 
GeneralRe: writing a windows service Pin
PIEBALDconsult17-Jan-10 5:15
mvePIEBALDconsult17-Jan-10 5:15 
GeneralRe: writing a windows service Pin
dan!sh 17-Jan-10 6:10
professional dan!sh 17-Jan-10 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.