52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
|
|
namespace VoiceCat.App.Forms;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Shows "Press any key…" and captures the next KeyDown as the PTT key.
|
||
|
|
/// Press Escape to cancel without changing the key.
|
||
|
|
/// </summary>
|
||
|
|
public sealed class PttKeyCaptureDialog : Form
|
||
|
|
{
|
||
|
|
private readonly Label _label;
|
||
|
|
|
||
|
|
public Keys CapturedKey { get; private set; }
|
||
|
|
|
||
|
|
public PttKeyCaptureDialog(Keys current)
|
||
|
|
{
|
||
|
|
CapturedKey = current;
|
||
|
|
|
||
|
|
_label = new Label
|
||
|
|
{
|
||
|
|
Text = $"Current PTT key: {current}\n\nPress any key to set a new PTT key,\nor press Escape to keep the current key.",
|
||
|
|
AutoSize = false,
|
||
|
|
Dock = DockStyle.Fill,
|
||
|
|
TextAlign = ContentAlignment.MiddleCenter,
|
||
|
|
TabIndex = 0,
|
||
|
|
};
|
||
|
|
|
||
|
|
AutoScaleMode = AutoScaleMode.Font;
|
||
|
|
ClientSize = new Size(340, 130);
|
||
|
|
Controls.Add(_label);
|
||
|
|
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||
|
|
KeyPreview = true;
|
||
|
|
MaximizeBox = false;
|
||
|
|
MinimizeBox = false;
|
||
|
|
StartPosition = FormStartPosition.CenterParent;
|
||
|
|
Text = "Set PTT key";
|
||
|
|
|
||
|
|
KeyDown += (_, e) =>
|
||
|
|
{
|
||
|
|
e.SuppressKeyPress = true;
|
||
|
|
if (e.KeyCode == Keys.Escape)
|
||
|
|
{
|
||
|
|
DialogResult = DialogResult.Cancel;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
CapturedKey = e.KeyCode;
|
||
|
|
DialogResult = DialogResult.OK;
|
||
|
|
}
|
||
|
|
Close();
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|