Question

I am new to C# and Windows Programming in general. I am trying to right a application where I need to perform certain actions based on which key was pressed. Say, I want to generate a message whenever 'Shift' key was pressed. I was thinking I could simply detect the keypress and print the message.

While googling different ideas, I came across the term hotkey and the process of registering a hotkey. I am not sure why would someone want to register a 'hotkey' when they can simply detect whether a key or a combination of keys was pressed using simple key APIs. I read that hotkeys are useful when the form is out of focus, but I do not know what that means.

What exactly does a 'form' mean. For example, if I have Microsoft word open, and I have the edit menu open, and I press Ctrl-C, is that considered a hotkey. What if the edit menu is not open? I am treating the edit menu as a form.

Thanks

Était-ce utile?

La solution

First of all a Form in Visual Studio is a Window. So if the form is out of focus it means the window is not selected.

As a beginner you can use the Events tab (in the properties of the window). You can use the KeyUp, KeyPress, KeyDown events and use "case" to set different roles to different key presses.

I hope this was helpful.

Autres conseils

Registering hotkey allows you to attach any method to run whenever in application you are placed now. Detecting key press is provided only when you are waiting for it literally.

Out of focus means that you are leaving some window and switch to another (in general Focus works on all UI controls - it is like, what the click/key press will be associated with - with button, form, label, etc).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top