diff --git a/Mk0.Software.ImageSorter/Inpaint.cs b/Mk0.Software.ImageSorter/Inpaint.cs index adeb8e9..c443d82 100644 --- a/Mk0.Software.ImageSorter/Inpaint.cs +++ b/Mk0.Software.ImageSorter/Inpaint.cs @@ -7,7 +7,7 @@ using System.IO; namespace Mk0.Software.ImageSorter { - public partial class Inpaint : Form + public partial class Inpaint : Form, IKeyboardHandler { private readonly string url; private readonly string file; @@ -31,14 +31,11 @@ namespace Mk0.Software.ImageSorter settings.LogSeverity = LogSeverity.Disable; if (!Cef.IsInitialized) { - //Perform dependency check to make sure all relevant resources are in our output directory. var initialized = Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); if (!initialized) { MessageBox.Show("Cef.Initialized failed, check the log file for more details."); - - //Shutdown(); } } @@ -46,6 +43,7 @@ namespace Mk0.Software.ImageSorter { DownloadHandler = new DownloadHandler(), MenuHandler = new MenuHandler(), + KeyboardHandler = this, TabIndex = 0 }; this.Controls.Add(browser); @@ -109,7 +107,7 @@ namespace Mk0.Software.ImageSorter InitialDelay = 1000, ReshowDelay = 500 }; - t2.SetToolTip(buttonReload, "Inpaint neu laden (Strg + F5)"); + t2.SetToolTip(buttonReload, "Inpaint neu laden (F2)"); } private void CopyPasteImage() @@ -132,14 +130,57 @@ namespace Mk0.Software.ImageSorter } private void ButtonPaste_Click(object sender, EventArgs e) + { + Paste(); + } + + private void Paste() { CopyPasteImage(); } private void ButtonReload_Click(object sender, EventArgs e) + { + Reload(); + } + + private void Reload() { browser.Reload(); CopyPasteImage(); } + + public bool OnPreKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) + { + isKeyboardShortcut = true; + return false; + } + + public bool OnKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) + { + if (type == KeyType.KeyUp && Enum.IsDefined(typeof(Keys), windowsKeyCode)) + { + var key = (Keys)windowsKeyCode; + switch (key) + { + case Keys.F2: + this.BeginInvoke(new Action(() => { + Reload(); + })); + break; + case Keys.F5: + this.BeginInvoke(new Action(() => { + Paste(); + })); + break; + case Keys.Escape: + this.BeginInvoke(new Action(() => { + this.Close(); + })); + break; + } + } + return false; + } } }