| View previous topic :: View next topic |
| Author |
Message |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Thu Dec 04, 2008 8:53 pm Post subject: [C#]Hotkeys |
|
|
so, i've used premade hotkey.cs files i found on code project
i've heard of getasynckeystate, and register hotkey, i've tried both
in c#, whats the best way to process both?
i can process one hotkey with registerhotkey, but i can't process two for some reason
with getasynckeystate, is it really necesarry i use a timer to check?, and same problem with registerhotkey, but i never tried
BASICALLY, please post a snippets for both, preferably to process the f1 and f2 keys
thanks a bunch!
for c#
| Code: | protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
const int VK_F1 = 0x71;
switch (m.Msg)
{
case WM_HOTKEY:
MessageBox.Show("F1 Pressed");
break;
}
base.WndProc(ref m);
} |
can somebody get that to work, for f1 AND f2?
_________________
Last edited by yoyonerd on Thu Dec 04, 2008 9:09 pm; edited 1 time in total |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Dec 04, 2008 8:59 pm Post subject: |
|
|
With RegisterHotKey you have to respond to WM_HOTKEY. When you register one, you set the ID for it.
http://msdn.microsoft.com/en-us/library/ms646279(VS.85).aspx
wParam is where you'll be checking the ID's... You will need to override WndProc to handle the message, of course.
With GetAsyncKeyState, yes you need to run it on a timer, or a loop / thread, just like the name would hint at.
|
|
| Back to top |
|
 |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Thu Dec 04, 2008 9:24 pm Post subject: |
|
|
can you try and fix my code?
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Dec 04, 2008 9:45 pm Post subject: |
|
|
| yoyonerd wrote: | | can you try and fix my code? |
Like I said, check wParam within WM_HOTKEY. That is what is wrong.
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Fri Dec 05, 2008 7:23 pm Post subject: |
|
|
Check out my keyboard hook.
_________________
|
|
| Back to top |
|
 |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Sun Dec 07, 2008 12:34 pm Post subject: |
|
|
nvm, figured out what slovach was saying >.<
thanks though, and yeah samurai, i've looked at your keyboard hook before xD
_________________
|
|
| Back to top |
|
 |
arigity Advanced Cheater
Reputation: 0
Joined: 03 Jul 2008 Posts: 65 Location: middle of nowhere.
|
Posted: Sun Dec 07, 2008 1:31 pm Post subject: |
|
|
i would like to point out that system.windows.forms.keys should be the entire keys enum there should be little need to declare them elsewhere.
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Dec 07, 2008 6:27 pm Post subject: |
|
|
| yoyonerd wrote: | nvm, figured out what slovach was saying >.<
thanks though, and yeah samurai, i've looked at your keyboard hook before xD |
also, you can use the Keys class, instead of defining everything yourself.
|
|
| Back to top |
|
 |
|