diff --git a/MorseTrainer/Form1.Designer.cs b/MorseTrainer/Form1.Designer.cs
index 918a2b5..aeb9a65 100644
--- a/MorseTrainer/Form1.Designer.cs
+++ b/MorseTrainer/Form1.Designer.cs
@@ -171,6 +171,7 @@
this.txtAnalysis.Location = new System.Drawing.Point(20, 288);
this.txtAnalysis.Name = "txtAnalysis";
this.txtAnalysis.ReadOnly = true;
+ this.txtAnalysis.ShortcutsEnabled = false;
this.txtAnalysis.Size = new System.Drawing.Size(884, 177);
this.txtAnalysis.TabIndex = 8;
this.txtAnalysis.Text = "";
diff --git a/MorseTrainer/Form1.cs b/MorseTrainer/Form1.cs
index 116ab17..df64302 100644
--- a/MorseTrainer/Form1.cs
+++ b/MorseTrainer/Form1.cs
@@ -28,7 +28,7 @@ using System.Windows.Forms;
namespace MorseTrainer
{
- public partial class Form1 : Form
+ public partial class Form1 : KeyCaptureForm
{
[Flags]
public enum ControlToUpdate
@@ -268,6 +268,7 @@ namespace MorseTrainer
private void _runner_MorseEnter(object sender, EventArgs e)
{
_player.Start();
+ InputtingKeys = true;
String word = _charGenerator.CreateRandomString();
_builder.StartBuildAsync(word, new AsyncCallback(WaveReadyCallback));
}
@@ -315,6 +316,7 @@ namespace MorseTrainer
Analyze();
btnStartStop.Text = "Start";
btnStartStop.Enabled = true;
+ InputtingKeys = false;
}
}
@@ -1261,19 +1263,64 @@ namespace MorseTrainer
{
key = MorseInfo.PROSIGN_AR;
}
- String expanded = MorseInfo.ExpandProsigns(key.ToString()).ToUpperInvariant();
- txtAnalysis.AppendText(expanded);
- _recorded.Append(expanded);
- processed = true;
+
+ if (key == '\b')
+ {
+ // backspace
+ if (txtAnalysis.TextLength > 0)
+ {
+ //txtAnalysis.SuspendLayout();
+ txtAnalysis.Select(txtAnalysis.TextLength-1, 1);
+ txtAnalysis.ReadOnly = false;
+ txtAnalysis.SelectedText = "";
+ txtAnalysis.ReadOnly = true;
+ //txtAnalysis.Text = txtAnalysis.Text.Remove(txtAnalysis.TextLength - 1);
+ //txtAnalysis.Select(txtAnalysis.TextLength, 0);
+ //txtAnalysis.ResumeLayout();
+ }
+ processed = true;
+ }
+ else if (key == '\u001b')
+ {
+ // esc
+ processed = true;
+ }
+ else if (key == '\r')
+ {
+ // enter
+ processed = true;
+ }
+ else
+ {
+ String expanded = MorseInfo.ExpandProsigns(key.ToString()).ToUpperInvariant();
+ txtAnalysis.AppendText(expanded);
+ _recorded.Append(expanded);
+ processed = true;
+ }
return processed;
}
+ protected override bool IsInputKey(Keys keyData)
+ {
+ bool retval = base.IsInputKey(keyData);
+ return retval;
+ //return base.IsInputKey(keyData);
+ }
+
+ //protected override bool ProcessMorseKey(Keys keyData)
+ //{
+ // //return UserKey(keyData);
+ // return true;
+ //}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (_runner.IsListenMode)
{
- e.Handled = UserKey(e.KeyChar);
+ if (UserKey(e.KeyChar))
+ {
+ e.Handled = true;
+ }
}
}
#endregion
diff --git a/MorseTrainer/KeyCaptureForm.cs b/MorseTrainer/KeyCaptureForm.cs
new file mode 100644
index 0000000..6bc02ec
--- /dev/null
+++ b/MorseTrainer/KeyCaptureForm.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace MorseTrainer
+{
+ public class KeyCaptureForm : System.Windows.Forms.Form
+ {
+ public KeyCaptureForm() : base()
+ {
+ _inputtingKeys = false;
+ }
+
+ ///
+ /// This override will suppress system beeps for the key in the richtextbox
+ ///
+ ///
+ ///
+ protected override bool ProcessKeyPreview(ref Message m)
+ {
+ if (_inputtingKeys && m.Msg == 0x0100)
+ {
+ switch ((uint)m.WParam)
+ {
+ case 8: // BackSpace
+ case 13: // Enter
+ case 46: // DEL
+ return true;
+ default:
+ break;
+ }
+ }
+ return base.ProcessKeyPreview(ref m);
+ }
+
+ ///
+ /// When inputting keys, the form handles all key input
+ ///
+ public bool InputtingKeys
+ {
+ get
+ {
+ return _inputtingKeys;
+ }
+ set
+ {
+ _inputtingKeys = value;
+ }
+ }
+
+ private bool _inputtingKeys;
+ }
+}
diff --git a/MorseTrainer/MorseTrainer.csproj b/MorseTrainer/MorseTrainer.csproj
index 3de39ab..aadf10c 100644
--- a/MorseTrainer/MorseTrainer.csproj
+++ b/MorseTrainer/MorseTrainer.csproj
@@ -55,6 +55,9 @@
+
+ Form
+
diff --git a/MorseTrainer/ToneGenerator.cs b/MorseTrainer/ToneGenerator.cs
index f970d80..19e6234 100644
--- a/MorseTrainer/ToneGenerator.cs
+++ b/MorseTrainer/ToneGenerator.cs
@@ -339,8 +339,9 @@ namespace MorseTrainer
else if (sample > actualSamples - fade)
{
envelope = (float)(actualSamples - sample) / (float)fade;
- }
- float instantaneous = (float)Math.Sin((float)(sample % _samplesPerCycle) / _samplesPerCycle * (2 * Math.PI )) * _volume * envelope;
+ }
+ float volume = _volume * _volume * _volume;
+ float instantaneous = (float)Math.Sin((float)(sample % _samplesPerCycle) / _samplesPerCycle * (2 * Math.PI )) * volume * envelope;
waveform[sample] = (Int16)(32767 * instantaneous);
}