winforms - Shortcut in Visual Studio - Windows Form Application while other Window is active -


i want use shortcut in windows form app , found following code.

protected override bool processcmdkey(ref message msg, keys keydata) {      if (keydata == (keys.enter)) {        messagebox.show("hello world!");        return true;      }      return base.processcmdkey(ref msg, keydata);    } 

but works, if window active. how can use shortcut if different window active?

you use single entry point message catching , dispatching in base form.

base form

public class baseform : form {     public void mymessage(hwnd:hwnd)     {        ...        case msg_specific_action_1 : handled=this.doonspecificaction1();        ...      }      protected bool doonspecificaction1(){ return=false;} } 

base form descendant

public class mycustomform : baseform {     protected override bool doonspecificaction1()     {         messagebox.show("hello");         return true;         } } 

edit - global keyboardhook

if looking trap key events in other applications need use keyboard hook. here nice article describing using setwindowshookex.


Comments

Popular posts from this blog

python - How to create jsonb index using GIN on SQLAlchemy? -

PHP DOM loadHTML() method unusual warning -

c# - TransactionScope not rolling back although no complete() is called -