vb.net - Common keypresses in multiple project solution -


i have multiple project solution , need service keystrokes common projects of solution.
example if press ctrl+alt+right shift anywhere , time in of included project "something" happens can detect keystroke immediately.

for projects have common code in additional project included in other projects reference "common.dll" may right place put code.

any idea on how make task , how code should like?

i thinking on detecting keystrokes @ prefilter message can't make without help.
maybe different kind of solution better 1 think?

windows forms raises keyboard events not need go low level handling window messages yourself. standardise approach across multiple forms , projects, create common dll project , add reference in of other projects. create static class (module in vb) in common project along lines of code below.

imports system.windows.forms  public module keypresshandler      ''' <summary>     ''' connects <see cref="form.keydown"/> event handler specified windows form     ''' </summary>     public sub connectkeyhandler(form form)         addhandler form.keydown, new keyeventhandler(addressof keypresshandler.keydownhandler)     end sub      ''' <summary>     ''' handles keydown event windows form     ''' </summary>      private sub keydownhandler(sender object, e keyeventargs)        if (e.keydata.hasflag(keys.control) andalso e.keydata.hasflag(keys.alt) andalso e.keydata.hasflag(keys.shift))             '' whatever want here         end if     end sub  end module 

then in code-behind of each form, in constructor, add following line of code:

common.keypresshandler.connectkeyhandler(me) 

(so end looking this):

public class form1      public sub new()          ' call required designer.         initializecomponent()          ' add initialization after initializecomponent() call.         common.keypresshandler.connectkeyhandler(me)     end sub  end class 

the hasflag method on enums added in .net 4, if using version before logic little more long winded:

if ((e.keydata , keys.control = keys.control) andalso (e.keydata , keys.alt = keys.alt) andalso (e.keydata , keys.shift = keys.shift)) 

there still problem detecting right shift key opposed shift key. couldn't find working way differentiate left shift key, although looked using rshift supposed it. 1 solution might call windows api function getkeystate (see http://www.pinvoke.net/default.aspx/user32.getkeystate) vk_rshift constant. historical reason left , right shift key distinction being later addition windows undifferentiated shift keys.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -