Search code examples
c#awesomium

How can I disable Ctrl+p in Awesomium?


I'm trying to disable the ctrl+p command in a WPF application with Awesomium. When you press ctrl+p Awesomium saves a pdf from the document.

I try with JavaScript and c# code but nothing works.

JS (it open the window before the function):

$(document).ready(function (e) {
    $('body').keydown(function (event) {
        // alert('this');
        if (event.which == 80 && event.ctrlKey) {
            return false;
            //alert('me');   
        }
    });
});

C# (just ignore it):

myAwesomium.KeyDown +) KeyyDown;

private void KeyyDown(object sender, KeyEventArgs e)
  {
    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
  { 
    #Something 
  }
}

Solution

  • you should use PreviewKeyDown for that. There you need to set e.Handled = true, this will stop processing the keyhandling.

    private void WebControl1_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        e.Handled = true;
    }
    

    Hint: You should also set the ContextMenu of the WebControl to a new ContextMenu to prevent printing via the contextmenu entry.

    Hope that it help.