 <p>The error you are receiving in your code is due to the following line <code>if (character.ToString() = "space")</code></p> <p>You are attempting to assign the string literal "space" to <code>character.ToString()</code>, I also have this error in my comment which I can't edit anymore.</p> <p>Here's a snippet that will check the key code against an enum instead of a string, it will then call the <code>HandleComparison</code> method if Space was pressed, and then clear out the <code>StringBuilder</code></p> <p>The only issue I found here is that pressing Shift will prefix the string with <code>&lt;shift&gt;</code>, so some additional logic will have to be applied for action keys, but this is a base to get you started with a working code sample.</p> <p>I hope this helps.</p> <pre><code>class Program { private static StringBuilder builder; static void Main(string[] args) { using (var api = new KeystrokeAPI()) { builder = new StringBuilder(); api.CreateKeyboardHook(HandleKeyPress); Application.Run(); } } private static void HandleKeyPress(KeyPressed obj) { // To be more reliable, lets use the KeyCode enum instead if (obj.KeyCode == KeyCode.Space) { // Spacebar was pressed, let's check the word and flush the StringBuilder HandleComparison(builder.ToString()); builder.Clear(); return; } // Space wasn't pressed, let's add the word to the StringBuilder builder.Append(obj); } // Handle comparison logic here, I.E check word if exists on blacklist private static void HandleComparison(string compareString) { Console.WriteLine(compareString); } } </code></pre>