none
Building an application to run in the background RRS feed

  • Question

  • hi all
    I am working in .NET 2.0. I am in a great fuss as I want to build an application which runs in the background an translate the keystrokes of user as directed.

    When the user starts my application it will start in the background. Then the user can start any of the application he/she needed or wish but the keystrokes provided by the user should be translated as directed in my application and then showed to user.

    I don't understand from where to start.
    Please help me as it is urgent.

    Thanks in advance.

    • Moved by spacewrangler Friday, September 19, 2008 7:27 PM Not a tools question. (Moved from Building Development and Diagnostic Tools for .Net to Common Language Runtime)
    Thursday, September 18, 2008 11:21 AM

Answers

  • You'll have to use either GetAsyncKeyState() to log keystrokes, or use keyboard hooks. See this.

    To hide your console when it starts up, use something like this:

     

    [DllImport("user32.dll")]  
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);  
     
    [DllImport("user32.dll")]  
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);  
     
     
    // add this to your main()  
     
    Console.Title = "FooBar";  
     
    IntPtr hWnd = FindWindow(null"FooBar");  
     
    if (hWnd != IntPtr.Zero)  
    {  
        ShowWindow(hWnd, 0); // this will hide the winodw  
    }  
     
     



     

    • Proposed as answer by Prithvi_Prabhu Saturday, September 20, 2008 2:16 PM
    • Marked as answer by Zhi-Xin Ye Tuesday, September 23, 2008 10:46 AM
    Saturday, September 20, 2008 2:16 PM

All replies

  • YOu have to look into the API or messaging system for Dot net,
    and catter the specific messages and bind your events to those.
    In that way you can get a start on it.
    Friday, September 19, 2008 11:37 PM
  • You'll have to use either GetAsyncKeyState() to log keystrokes, or use keyboard hooks. See this.

    To hide your console when it starts up, use something like this:

     

    [DllImport("user32.dll")]  
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);  
     
    [DllImport("user32.dll")]  
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);  
     
     
    // add this to your main()  
     
    Console.Title = "FooBar";  
     
    IntPtr hWnd = FindWindow(null"FooBar");  
     
    if (hWnd != IntPtr.Zero)  
    {  
        ShowWindow(hWnd, 0); // this will hide the winodw  
    }  
     
     



     

    • Proposed as answer by Prithvi_Prabhu Saturday, September 20, 2008 2:16 PM
    • Marked as answer by Zhi-Xin Ye Tuesday, September 23, 2008 10:46 AM
    Saturday, September 20, 2008 2:16 PM
  • Hi

    This is my view on solving… let me know if any better way

     

    In VC++ We use to have hooks like Keyboard , Message, Mouse

     

    In C#.net you need to see keyboard class that will have all evens like onKeypresEvent Arg/keydown to capture the key and Convert to ASCII code to find the character.

     

    So you need to do this as a background process. I prefer to use thread to capture the even and store.

     

    To make a communication between your background application to foreground application you need to have some kind of socket/message queue (costly) to transfer online to your background application.

     

    Regards
    Venkat

    Tuesday, September 23, 2008 12:12 PM
  • I m thankful to all of you
    especially to prithvi prabhu
    Your reply has worked for me
    I had gone as you suggested
    and I had done what i want
    Friday, September 26, 2008 7:14 AM