Disable specific Keyboard Keys – Single Line of Code


Hey Friends,

I saw many people asking how to disable specific keys from Keyboards like for example How to Disable Enter Key , Though I never got this need 🙂 but eventually requirements has no limits hence I decided to find it out and introduce it here in my Blog.


InputFromKeyboard – System.Windows.Input.Keyboard.’PresentationCore, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35′

InputKey – System.Windows.Input.Key.’WindowsBase, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35′

Enable RunOnClient Property as Yes for both the.NET Variables

You just need to write the above code highlighted, What it will do is when the confirmation Dialogues pops up then you need to Press Yes from MOUSE instead of the Enter Key from Keyboard to execute the further piece of Codes. If you will Press Enter from Keyboard then EXIT statement will Run and system will leave the execution