windows mobile - Capture Left/Right Soft Key press -- C# .net CF 3.5 -
my application running on handheld device running windows mobile 6.5. want able capture left/right soft key button presses within application , take user "home" form or form used inside application. @ os level, these soft keys set go calendar/contacts respectively, inside application these buttons mentioned above. how go capturing or intercepting these soft key button presses inside of compact framework? have done little research , have seen references registering hot key? appreciated.
side note: application uses mainmenu control left/right soft keys not control menu selections.
try this:
public class hbuttons : system.windows.forms.form { private mainmenu mainmenu1; private menuitem mnuback; mymessagewindow messagewindow; public hbuttons() { initializecomponent(); this.messagewindow = new mymessagewindow(this); registerhkeys.registerrecordkey(this.messagewindow.hwnd); } protected override void dispose(bool disposing) { registerhkeys.unregisterrecordkey(); base.dispose(disposing); } public void buttonpressed(int button) { switch (button) { case (int)keyshardware.vk_app1: messagebox.show("vk_app1 pressed!"); break; case (int)keyshardware.greenphonebutton: messagebox.show("greenphonebutton pressed!"); break; case (int)keyshardware.redphonebutton: messagebox.show("redphonebutton pressed!"); break; case (int)keyshardware.vk_tsoft1: messagebox.show("vk_tsoft1 pressed!"); break; } } private void initializecomponent() { this.mainmenu1 = new system.windows.forms.mainmenu(); this.mnuback = new system.windows.forms.menuitem(); this.suspendlayout(); // // mainmenu1 // this.mainmenu1.menuitems.add(this.mnuback); // // mnuback // this.mnuback.text = "back"; this.mnuback.click += new system.eventhandler(this.mnuback_click); // // hbuttons // this.autoscalemode = system.windows.forms.autoscalemode.inherit; this.clientsize = new system.drawing.size(240, 268); this.menu = this.mainmenu1; this.minimizebox = false; this.name = "hbuttons"; this.text = "hw buttons"; this.resumelayout(false); } private void mnuback_click(object sender, eventargs e) { this.close(); } } public class mymessagewindow : messagewindow { public const int wm_hotkey = 0x0312; hbuttons example; public mymessagewindow(hbuttons anexample) { this.example = anexample; } 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 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.vk_app1); registerhotkey(hwnd, (int)keyshardware.vk_app1, keymodifiers.windows, (int)keyshardware.vk_app1); unregisterfunc1(keymodifiers.none, (int)keyshardware.greenphonebutton); registerhotkey(hwnd, (int)keyshardware.greenphonebutton, keymodifiers.none, (int)keyshardware.greenphonebutton); unregisterfunc1(keymodifiers.none, (int)keyshardware.redphonebutton); registerhotkey(hwnd, (int)keyshardware.redphonebutton, keymodifiers.none, (int)keyshardware.redphonebutton); unregisterfunc1(keymodifiers.none, (int)keyshardware.vk_tsoft1); registerhotkey(hwnd, (int)keyshardware.vk_tsoft1, keymodifiers.none, (int)keyshardware.vk_tsoft1); } public static void unregisterrecordkey() { unregisterfunc1(keymodifiers.windows, (int)keyshardware.vk_app1); unregisterfunc1(keymodifiers.none, (int)keyshardware.greenphonebutton); unregisterfunc1(keymodifiers.none, (int)keyshardware.redphonebutton); unregisterfunc1(keymodifiers.none, (int)keyshardware.vk_tsoft1); } } ///// <summary> ///// summary description 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, //0xc1 // hardware2 = 194, // hardware3 = 195, // hardware4 = 196, // hardware5 = 197 //} public enum keyshardware : int { vk_f1 = 0x70, vk_f2 = 0x71, vk_f3 = 0x72, vk_f4 = 0x73, vk_f5 = 0x74, vk_f6 = 0x75, vk_f7 = 0x76, vk_f8 = 0x77, vk_f9 = 0x78, vk_f10 = 0x79, vk_f11 = 0x7a, vk_f12 = 0x7b, vk_tsoft1 = vk_f1, // softkey 1 vk_tsoft2 = vk_f2, // softkey 2 vk_ttalk = vk_f3, // talk = green phone button vk_tend = vk_f4, // end = red phone button vk_app1 = 0xc1, // 6 other hardware buttons vk_app2 = 0xc2, vk_app3 = 0xc3, vk_app4 = 0xc4, vk_app5 = 0xc5, vk_app6 = 0xc6, redphonebutton = vk_tend, greenphonebutton = vk_ttalk }
Comments
Post a Comment