Skip to main content

code for c# hotkey register/unregister

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [.NET Compact Framework Development] >> .NET Compact Framework forum for C# >> code for c# hotkey register/unregister Page: [1]
Login
Message << Older Topic   Newer Topic >>
code for c# hotkey register/unregister - 10/19/2005 1:03:22 PM   
mtwal

 

Posts: 42
Score: 0
Joined: 8/4/2005
Status: offline
Thanks Pete for your help on my last post, and whoever is responsible for this code.  I had it, from a while back and just found it again.  I was only able to find it in vb on this site, so here it is in C# if anyone is interested:

using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
Microsoft.WindowsCE.Forms;
using
System.Runtime.InteropServices;
using
OpenNETCF.Diagnostics;
namespace
HHET
{
/// <summary>
/// Summary description for hwButtons.
/// </summary>
public class hwButtons
{
public hwButtons()
{
HButtons theBtns =
new HButtons();
}
}
public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8,
Modkeyup = 0x1000,
}
public enum KeysHardware : int
{
Hardware1 = 193,
Hardware2 = 194,
Hardware3 = 195,
Hardware4 = 196,
Hardware5 = 197
}
public class HButtons : System.Windows.Forms.Form
{
myMessageWindow messageWindow;
public HButtons()
{
this.messageWindow = new myMessageWindow(this); RegisterHKeys.RegisterRecordKey(this.messageWindow.Hwnd);
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}

public void ButtonPressed(int button)
{
switch(button)
{
case (int) KeysHardware.Hardware1:
MessageBox.Show("Button 1 pressed!");

break;
case (int) KeysHardware.Hardware2:
MessageBox.Show("Button 2 pressed!");
break;
case (int) KeysHardware.Hardware3:
MessageBox.Show("Button 3 pressed!");
break;
case (int) KeysHardware.Hardware4:
MessageBox.Show("Button 4 pressed!");
break;
}
}
}
public class myMessageWindow : MessageWindow
{
public const int WM_HOTKEY=0x0312;
HButtons example;
public myMessageWindow(HButtons example)
{
this.example = example;
}
protected override void WndProc(ref Message msg)
{
switch(msg.Msg)
{
case WM_HOTKEY:
example.ButtonPressed(msg.WParam.ToInt32());
return;
}
base.WndProc(ref msg);
}
}
public class RegisterHKeys
{
[DllImport("coredll.dll", SetLastError=
true)]
public static extern bool RegisterHotKey(
IntPtr hWnd,
// handle to window
int id, // hot key identifier
KeyModifiers Modifiers,
// key-modifier options
int key //virtual-key code
);
[ DllImport("coredll.dll")]
private static extern bool UnregisterFunc1(KeyModifiers
modifiers,
int keyID);
public static void RegisterRecordKey(IntPtr hWnd)
{
UnregisterFunc1(KeyModifiers.Windows, (
int)KeysHardware.Hardware1);
RegisterHotKey(hWnd, (
int) KeysHardware.Hardware1, KeyModifiers.Windows, (int) KeysHardware.Hardware1);

UnregisterFunc1(KeyModifiers.Windows, (
int)KeysHardware.Hardware2);
RegisterHotKey(hWnd, (
int) KeysHardware.Hardware2, KeyModifiers.Windows, (int) KeysHardware.Hardware2);
UnregisterFunc1(KeyModifiers.Windows, (
int)KeysHardware.Hardware3);
RegisterHotKey(hWnd, (
int) KeysHardware.Hardware3, KeyModifiers.Windows, (int) KeysHardware.Hardware3);
UnregisterFunc1(KeyModifiers.Windows, (
int)KeysHardware.Hardware4);
RegisterHotKey(hWnd, (
int) KeysHardware.Hardware4, KeyModifiers.Windows, (int) KeysHardware.Hardware4);
}
}
}
Post #: 1
Page:   [1]
All Forums >> [.NET Compact Framework Development] >> .NET Compact Framework forum for C# >> code for c# hotkey register/unregister Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.5.5 Unicode

0.063