c# - How to stop Control-I from inserting a tab in a UWP TextBox at CoreWindow scope? -


strange behavior (to me) when have textbox in uwp app.

  • create universal, blank app uwp app in windows 10.
  • add textbox default grid code:
    <textbox text="there's not spam in it" name="textbox" />
  • build , run application.
  • click inside of textbox
  • type control-i.

a tab inserted.

what causes behavior?

i'm trying set window level shortcuts in windows 10 application hooking handler window.current.corewindow.keydown, think that's late in event game catch control-i's tab insertion , call handled. that, think textbox's keydown handled before corewindow's event occurs.

so i'm settling handling event on each textbox whenever selects control-i this...

edit xaml this:

<textbox text="there's not spam in it"      name="textbox" keydown="textbox_keydown" acceptsreturn="true" /> 

add event handler:

private void textbox_keydown(object sender, keyroutedeventargs e) {     if (e.originalkey.equals(virtualkey.i)          && window.current.corewindow.getkeystate(virtualkey.control)         .hasflag(corevirtualkeystates.down))     {         this.textbox.selectedtext += "x";         e.handled = true;     } } 

... seems work okay, except have slap "window" scope event handler control-i each textbox (or extend textbox, both of seem crazy seems non-standard keyboard shortcut).

so i'm asking action inserts tab textbox when control-i pressed, , if there's better way avoid action @ corewindow level. better means of capturing keyboard shortcuts @ corewindow level (eg, ctrl-k means insert link) appreciated, wouldn't answer "real" question.

the best solution i've found date insert event handler keydown eat ctrl-i.

i have fuller solution on github addresses , other issues here, here's operative ctrl-i eating code:

public uwpbox() : base() {     this.keydown += this.keydownhandler; }  public virtual async void keydownhandler(object sender, keyroutedeventargs e) {     bool isctrldown = window.current.corewindow.getkeystate(virtualkey.control)         .hasflag(corevirtualkeystates.down);      try     {         switch (e.originalkey)         {             case virtualkey.i:                 // first, kill default "ctrl-i inserts tab" action.                 if (isctrldown)                 {                     e.handled = true;                     this.handlectrli(); // in case want                                          // different ctrl-i                 }                 break;              // "fixes" ctrl-v , tab removed.             // fuller solution here: https://github.com/ruffin--/uwpbox         }     }     catch (exception ex)     {         system.diagnostics.debug.writeline(             datetime.now.tostring("yyyy-mm-dd hh:mm:ss.fff") + ": "              + ex.message);     } }  public virtual void handlectrli() {     system.diagnostics.debug.writeline("ctrl-i pressed."); } 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

c - getting error: cannot take the address of an rvalue of type 'int' -

How to merge four videos on one screen with ffmpeg -