Skip to content

Commit 3e7dd9d

Browse files
authored
Merge pull request #2 from WindowsLogic-Productions/fix-arrow-keys
Added function to ignore arrow keys as navigation
2 parents 8211696 + 82039c4 commit 3e7dd9d

10 files changed

+33
-2
lines changed

Main.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public partial class Main : Form
1616
public Main()
1717
{
1818
InitializeComponent();
19+
this.KeyPreview = true;
1920
// saveToolStripMenuItem.Text = "Save As..."; //Default name of command
2021
}
2122

@@ -332,6 +333,7 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
332333

333334

334335
}
336+
335337
// This function used for shorten code
336338
public void GetKeyCode(int target1, Button target2, int index, bool joy = false)
337339
{
@@ -346,6 +348,7 @@ public void GetKeyCode(int target1, Button target2, int index, bool joy = false)
346348
if (joy) target2.Text = "Joy" + Convert.ToInt32(str);
347349
else target2.Text = ButtonKeys[Convert.ToInt32(str)];
348350
}
351+
349352
// Since C# can't use byte[] == byte[]
350353
public bool compare2arrays(byte[] arr1, byte[] arr2)
351354
{
@@ -374,13 +377,30 @@ private void Form1_KeyDown(object sender, KeyEventArgs e)
374377
targetButton.Text = ButtonKeys[e.KeyValue];
375378
buttons[Convert.ToInt32(targetButton.Tag)] = e.KeyValue;
376379
Console.WriteLine(e.KeyValue);
380+
e.Handled = true;
377381
}
378382
if (e.KeyCode == Keys.Enter)
379383
{
380384
targetButton.Text = ButtonKeys[e.KeyValue];
381385
buttons[Convert.ToInt32(targetButton.Tag)] = e.KeyValue;
382386
Console.WriteLine(e.KeyValue);
387+
e.Handled = true;
388+
}
389+
}
390+
391+
// Prevent default behavior to read arrow keys as navigation keys
392+
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
393+
{
394+
if (input_key && (keyData == Keys.Left || keyData == Keys.Right || keyData == Keys.Up || keyData == Keys.Down))
395+
{
396+
input_key = false;
397+
int keyCode = (int)keyData;
398+
targetButton.Text = ButtonKeys[keyCode];
399+
buttons[Convert.ToInt32(targetButton.Tag)] = keyCode;
400+
Console.WriteLine(keyCode);
401+
return true; // Suppress default behavior
383402
}
403+
return base.ProcessCmdKey(ref msg, keyData);
384404
}
385405

386406
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)

bin/Debug/Controls.exe

1 KB
Binary file not shown.

bin/Debug/Controls.pdb

0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
da59c910900cd1cf13e3a8a27b3caf12aeea12af
1+
1eeeb82524111933bd54f0ef87a0d1fe3f914242

obj/Debug/Controls.csproj.FileListAbsolute.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ J:\Projects\FM2K-Controls\obj\Debug\Controls.csproj.CoreCompileInputs.cache
3737
J:\Projects\FM2K-Controls\obj\Debug\Controls.exe
3838
J:\Projects\FM2K-Controls\obj\Debug\Controls.pdb
3939
J:\Projects\FM2K-Controls\obj\Debug\Controls.About.resources
40+
D:\VisualStudio2017\FM2K-Controls\bin\Debug\Controls.exe.config
41+
D:\VisualStudio2017\FM2K-Controls\bin\Debug\Controls.exe
42+
D:\VisualStudio2017\FM2K-Controls\bin\Debug\Controls.pdb
43+
D:\VisualStudio2017\FM2K-Controls\obj\Debug\Controls.csprojAssemblyReference.cache
44+
D:\VisualStudio2017\FM2K-Controls\obj\Debug\Controls.About.resources
45+
D:\VisualStudio2017\FM2K-Controls\obj\Debug\Controls.Main.resources
46+
D:\VisualStudio2017\FM2K-Controls\obj\Debug\Controls.Properties.Resources.resources
47+
D:\VisualStudio2017\FM2K-Controls\obj\Debug\Controls.csproj.GenerateResource.cache
48+
D:\VisualStudio2017\FM2K-Controls\obj\Debug\Controls.csproj.CoreCompileInputs.cache
49+
D:\VisualStudio2017\FM2K-Controls\obj\Debug\Controls.exe
50+
D:\VisualStudio2017\FM2K-Controls\obj\Debug\Controls.pdb
0 Bytes
Binary file not shown.
2.93 KB
Binary file not shown.

obj/Debug/Controls.exe

1 KB
Binary file not shown.

obj/Debug/Controls.pdb

0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
da59c910900cd1cf13e3a8a27b3caf12aeea12af
1+
1eeeb82524111933bd54f0ef87a0d1fe3f914242

0 commit comments

Comments
 (0)