From 442ba4f0c07d5d4c3abd8bce3da830cb5f1d79b2 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 1 Oct 2022 10:44:11 +0300 Subject: [PATCH] fixed #6494: Allow closing OCR form with Esc key --- ShareX/Tools/OCR/OCRForm.Designer.cs | 2 ++ ShareX/Tools/OCR/OCRForm.cs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/ShareX/Tools/OCR/OCRForm.Designer.cs b/ShareX/Tools/OCR/OCRForm.Designer.cs index 7b0d46677..cb4de85c1 100644 --- a/ShareX/Tools/OCR/OCRForm.Designer.cs +++ b/ShareX/Tools/OCR/OCRForm.Designer.cs @@ -164,9 +164,11 @@ private void InitializeComponent() this.Controls.Add(this.lblResult); this.Controls.Add(this.cbLanguages); this.Controls.Add(this.lblLanguage); + this.KeyPreview = true; this.Name = "OCRForm"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.Shown += new System.EventHandler(this.OCRForm_Shown); + this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OCRForm_KeyUp); ((System.ComponentModel.ISupportInitialize)(this.nudScaleFactor)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/ShareX/Tools/OCR/OCRForm.cs b/ShareX/Tools/OCR/OCRForm.cs index fc971da76..1841fd6a4 100644 --- a/ShareX/Tools/OCR/OCRForm.cs +++ b/ShareX/Tools/OCR/OCRForm.cs @@ -171,6 +171,14 @@ private async void OCRForm_Shown(object sender, EventArgs e) await OCR(bmpSource); } + private void OCRForm_KeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + Close(); + } + } + private async void btnSelectRegion_Click(object sender, EventArgs e) { FormWindowState previousState = WindowState;