473,394 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Multiple hotkeys [c#]

Markus
6,050 Expert 4TB
In a windows form application, I register a hotkey to be used throughout the application. However, I would also like a second hotkey to be registered and used, but this isn't too clear as to how to accomplish.

When the form loads, I do this (bearing in mind I have imported the DLLs previously)
Expand|Select|Wrap|Line Numbers
  1. RegisterHotKey(this.Handle, this.GetType().GetHashCode(), 2, (int)'A');
  2.  
Then I use the WndProc method to catch the hotkey. Like so,
Expand|Select|Wrap|Line Numbers
  1. protected override void WndProc(ref Message m)
  2.         {
  3.             if (m.Msg == 0x0312)
  4.                 CopyToClip();
  5.             base.WndProc(ref m);
  6.         }
This then runs the method CopyToClip().

Any ideas on how I can add another hotkey?
Nov 1 '08 #1
4 4165
Curtis Rutland
3,256 Expert 2GB
Let me ask you this...do you need the full Hotkey functionality? Or are you already going to be focused on the form?

If you are focused on the form, you can handle the KeyDown event, and test for several keys.
Nov 2 '08 #2
tlhintoq
3,525 Expert 2GB
Does something like this work?

Expand|Select|Wrap|Line Numbers
  1. if ((m.Msg == 0x0312) || (m.Msg == 0x314) || (m.Msg == 0x0327))
  2. {
  3.      // Do your thang
  4. }
  5. base.WndProc(ref m);
  6.  
Nov 2 '08 #3
Markus
6,050 Expert 4TB
Let me ask you this...do you need the full Hotkey functionality? Or are you already going to be focused on the form?

If you are focused on the form, you can handle the KeyDown event, and test for several keys.
No, the form doesn't have focus.

Does something like this work?

Expand|Select|Wrap|Line Numbers
  1. if ((m.Msg == 0x0312) || (m.Msg == 0x314) || (m.Msg == 0x0327))
  2. {
  3.      // Do your thang
  4. }
  5. base.WndProc(ref m);
  6.  
I wouldn't want the hotkeys to do the same thing, but I could seperate that into if/elses. The problem is: how do I know that CTRL + G would be 0x0323* ?

*Guess.
Nov 2 '08 #4
tlhintoq
3,525 Expert 2GB
No, the form doesn't have focus.



I wouldn't want the hotkeys to do the same thing, but I could seperate that into if/elses. The problem is: how do I know that CTRL + G would be 0x0323* ?

*Guess.
Maybe the best way is to look for the Windows message of key down (0x100) then check what key(s) are pressed.
Helpful article
Nov 2 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: skumar | last post by:
I need to access the Tabpages by hotkeys "alt+P" in case of "Principals" as one of the Tabpage. Also i need to underline the word "P" in "Principals" so that user is informed about the hotkey.If...
2
by: Hasan Ammar | last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be done with the usual alphanumeric keys, but what about function keys? or using ctrl/alt combinations? Does anybody have a...
1
by: Matthew Wells | last post by:
How do you prevent someone from using Ctrl+, (ctl + comma) or Ctl + . (Ctl + perios) to get to design view. I have all the normal properites turned off (Access special keys, F!!, etc) but nothing...
3
by: Matthew Wells | last post by:
I'm reposting because an idiot replied without reading the whole message. I've tried autokeys and it isn't working for this combination. Please read on. While in form view, how do you prevent...
2
by: Martin Hjärtmyr | last post by:
I have a program that uses Hotkeys! And they works just fine! I use this hotkeylib:...
3
by: Bernd Eichelsdorf | last post by:
Hi, I would like to add hotkeys to my webapp - it's running on a barcode scanner, that has got a number pad and the keys F1 - F4. I would like to add hotkeys, so that when the user presses F1,...
0
by: Octavius Khan | last post by:
How can I set system hotkey that will only work for specific applications. For example, I have a system tray application that uses hotkeys to perform certain tasks like placing text into a memo...
7
scriptick
by: scriptick | last post by:
Hi everyone, I want to register multiple global hotkeys. CTRL+A , SHIFT+B etc etc etc. I want to more clear : If i pressed : CTRL+A then a message will show (MessageBox.Show("Pavel,Tangal") If i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.