java - C# WinForms Key Bindings -


what closest equivalent of java's keybindings in c#? attempting port swing application c#, unclear method should use. here sample of java porting:

action goup = new abstractaction() {     @override     public void actionperformed(actionevent e) {         panel.uppressed = true;     } };  action stopup = new abstractaction() {     @override     public void actionperformed(actionevent e) {         panel.uppressed = false;     } };  inputmap getinputmap = panel.getinputmap(jcomponent.when_in_focused_window);  getinputmap.put(keystroke.getkeystroke("w"), "goup"); getinputmap.put(keystroke.getkeystroke("released w"), "stopup");  panel.getactionmap().put("goup", goup); panel.getactionmap().put("stopup", stopup); 

in winforms, not aware of inputmap. keyboard input handled in 1 of 2 ways:

  1. shortcut keys, i.e. menuitem.shortcut. assignable in designer, or in code. pressing associated key invoke menu item's click event handler(s). of course, use method requires action want take represented in ui menu item.
  2. various key event handling in ui. can complicated depending on needs, appropriate way, , primary way handle key input not associated menu item. simplest event keypress event. given example, want handle keydown , keyup can track actual state of key. note receive multiple keydown events auto-repeat kicks in key; if problem handler, you'll need track key state , key you've seen keydown, handle keydown event if you've seen corresponding keyup event.

note wpf have key binding model more similar inputmap. of course, syntax entirely different, breaks apart idea of menu items, commands, , key bindings, can mix , match necessary (and in particular, have key bindings don't correspond menu item). if using wpf option, might find part of transition easier (and part, since swing otherwise more winforms wpf :) ).


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -