Skip to content

Commit af3f1eb

Browse files
committed
Updated copyright and added macro functionality
Also added QueryPanel and Dialog from the Support module (in CardMaker and otherwise)
1 parent 788ad44 commit af3f1eb

36 files changed

+1809
-43
lines changed

Format/BaseIOConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////////
22
// The MIT License (MIT)
33
//
4-
// Copyright (c) 2021 Tim Stair
4+
// Copyright (c) 2022 Tim Stair
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal

Format/ConfigFileManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////////
22
// The MIT License (MIT)
33
//
4-
// Copyright (c) 2021 Tim Stair
4+
// Copyright (c) 2022 Tim Stair
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal

Format/InputConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////////
22
// The MIT License (MIT)
33
//
4-
// Copyright (c) 2021 Tim Stair
4+
// Copyright (c) 2022 Tim Stair
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal

Format/OutputConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////////
22
// The MIT License (MIT)
33
//
4-
// Copyright (c) 2021 Tim Stair
4+
// Copyright (c) 2022 Tim Stair
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal

Format/RemapEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////////
22
// The MIT License (MIT)
33
//
4-
// Copyright (c) 2021 Tim Stair
4+
// Copyright (c) 2022 Tim Stair
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal

Forms/KeyCaptureConfig.cs

Lines changed: 164 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////////
22
// The MIT License (MIT)
33
//
4-
// Copyright (c) 2021 Tim Stair
4+
// Copyright (c) 2022 Tim Stair
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal
@@ -137,6 +137,46 @@ private void exitMainToolStripMenuItem_Click(object sender, EventArgs e)
137137
Close();
138138
}
139139

140+
private void btnAddOutputString_Click(object sender, EventArgs e)
141+
{
142+
const string MACRO_STRING_KEY = "macro_string_key";
143+
var zQuery = new QueryPanelDialog("Enter String Macro", 400, false);
144+
zQuery.SetIcon(this.Icon);
145+
zQuery.AddTextBox("String", string.Empty, false, MACRO_STRING_KEY);
146+
if (DialogResult.OK != zQuery.ShowDialog(this))
147+
{
148+
return;
149+
}
150+
var sMacro = zQuery.GetString(MACRO_STRING_KEY);
151+
if (string.IsNullOrWhiteSpace(sMacro))
152+
{
153+
MessageBox.Show(this, "Please specify a string of output characters.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
154+
return;
155+
}
156+
var zCurrentInputConfig = (InputConfig)txtKeyIn.Tag;
157+
if (null == zCurrentInputConfig)
158+
{
159+
ShowKeysNotDefinedError();
160+
return;
161+
}
162+
163+
try
164+
{
165+
var zRemapEntry = new RemapEntry(zCurrentInputConfig, CreateOutputConfigFromCharacter(sMacro[0]));
166+
for (var nIdx = 1; nIdx < sMacro.Length; nIdx++)
167+
{
168+
zRemapEntry.AppendOutputConfig(CreateOutputConfigFromCharacter(sMacro[nIdx]));
169+
}
170+
if (!IsInputAlreadyDefined(zRemapEntry))
171+
{
172+
AddRemapEntryToListView(zRemapEntry, true);
173+
}
174+
}
175+
catch (Exception ex)
176+
{
177+
MessageBox.Show(this, "Unfortunately you have specified an unsupported character (at this time)." + ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
178+
}
179+
}
140180

141181
private void KeyCaptureConfig_FormClosing(object sender, FormClosingEventArgs e)
142182
{
@@ -212,7 +252,7 @@ private void txtKey_Leave(object sender, EventArgs e)
212252

213253
#endregion
214254

215-
#region AbstractDirtyForm overrides
255+
#region AbstractDirtyForm overrides
216256

217257
protected override bool SaveFormData(string sFileName)
218258
{
@@ -257,7 +297,7 @@ protected override bool OpenFormData(string sFileName)
257297

258298
#endregion
259299

260-
#region Menu Events
300+
#region Menu Events
261301

262302
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
263303
{
@@ -298,7 +338,7 @@ private void recentConfiguration_Click(object sender, EventArgs e)
298338

299339
#endregion
300340

301-
#region Control Events
341+
#region Control Events
302342

303343
private void listViewKeys_SelectedIndexChanged(object sender, EventArgs e)
304344
{
@@ -366,15 +406,27 @@ private void btnAdd_Click(object sender, EventArgs e)
366406
OutputConfig zOutputConfig = null;
367407
RemapEntry zRemapEntry = null;
368408
if (!RetrieveAddConfigs(ref zInputConfig, ref zOutputConfig, ref zRemapEntry)) return;
409+
AddRemapEntryToListView(zRemapEntry, true);
410+
}
369411

370-
var zItem = new ListViewItem(new string[] {
371-
zRemapEntry.GetInputString(),
372-
zRemapEntry.GetOutputString() });
373-
zItem.Tag = zRemapEntry;
412+
private void AddRemapEntryToListView(RemapEntry zRemapEntry, bool bMarkDirty)
413+
{
414+
var zItem = new ListViewItem(new string[]
415+
{
416+
zRemapEntry.GetInputString(),
417+
zRemapEntry.GetOutputString()
418+
})
419+
{
420+
Tag = zRemapEntry,
421+
ToolTipText = zRemapEntry.GetOutputString()
422+
};
374423
listViewKeys.Items.Add(zItem);
375424
listViewKeys.SelectedItems.Clear();
376425
zItem.Selected = true;
377-
MarkDirty();
426+
if (bMarkDirty)
427+
{
428+
MarkDirty();
429+
}
378430
}
379431

380432
private void btnAppend_Click(object sender, EventArgs e)
@@ -652,20 +704,26 @@ private bool RetrieveAddConfigs(ref InputConfig zInputConfig, ref OutputConfig z
652704

653705
zRemapEntry = new RemapEntry(zInputConfig, zOutputConfig);
654706

707+
// flip this result for indicator of a good remap entry
708+
return !IsInputAlreadyDefined(zRemapEntry);
709+
}
710+
711+
private bool IsInputAlreadyDefined(RemapEntry zNewRemapEntry)
712+
{
655713
// verify this is not already defined
656714
foreach (ListViewItem zListItem in listViewKeys.Items)
657715
{
658716
var zKeyOldDef = (RemapEntry)zListItem.Tag;
659-
if (zRemapEntry.GetHashCode() != zKeyOldDef.GetHashCode())
717+
if (zNewRemapEntry.GetHashCode() != zKeyOldDef.GetHashCode())
660718
{
661719
continue;
662720
}
663721

664722
MessageBox.Show(this, "Duplicate inputs are not allowed!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
665-
return false;
723+
return true;
666724
}
667725

668-
return true;
726+
return false;
669727
}
670728

671729
private bool RetrieveAppendConfigs(ref OutputConfig zOutputConfig, RemapEntry zRemapEntry)
@@ -706,6 +764,100 @@ private bool ValidateOutputHasAction(OutputConfig zOutputConfig)
706764
return true;
707765
}
708766

767+
private OutputConfig CreateOutputConfigFromCharacter(char cInput)
768+
{
769+
var bShift = false;
770+
var byteKey = GetKeysByte(cInput, ref bShift);
771+
var nFlags = (bShift ? (int)OutputConfig.OutputFlag.Shift : 0) |
772+
(int)OutputConfig.OutputFlag.Down | (int)OutputConfig.OutputFlag.Up;
773+
return new OutputConfig(nFlags, byteKey);
774+
}
775+
776+
private byte GetKeysByte(char cInput, ref bool bShift)
777+
{
778+
bShift = char.IsUpper(cInput);
779+
try
780+
{
781+
return (byte)(Keys)Enum.Parse(typeof(Keys), cInput.ToString(), true);
782+
}
783+
catch (Exception)
784+
{
785+
// HACK
786+
// ignore and try the switch
787+
}
788+
#warning HACK This is super limited to a very specific keyboard
789+
switch (cInput)
790+
{
791+
case ' ':
792+
return (byte)Keys.Space;
793+
case '!':
794+
bShift = true;
795+
return (byte)Keys.D1;
796+
case '@':
797+
bShift = true;
798+
return (byte)Keys.D2;
799+
case '#':
800+
bShift = true;
801+
return (byte)Keys.D3;
802+
case '$':
803+
bShift = true;
804+
return (byte)Keys.D4;
805+
case '%':
806+
bShift = true;
807+
return (byte)Keys.D5;
808+
case '^':
809+
bShift = true;
810+
return (byte)Keys.D6;
811+
case '&':
812+
bShift = true;
813+
return (byte)Keys.D7;
814+
case '*':
815+
bShift = true;
816+
return (byte)Keys.D8;
817+
case '(':
818+
bShift = true;
819+
return (byte)Keys.D9;
820+
case ')':
821+
bShift = true;
822+
return (byte)Keys.D0;
823+
case '~':
824+
bShift = true;
825+
return (byte)Keys.Oemtilde;
826+
case '{':
827+
bShift = true;
828+
return (byte)Keys.OemOpenBrackets;
829+
case '}':
830+
bShift = true;
831+
return (byte)Keys.Oem6;
832+
case '|':
833+
bShift = true;
834+
return (byte)Keys.Oem5;
835+
case ':':
836+
bShift = true;
837+
return (byte)Keys.Oem1;
838+
case '"':
839+
bShift = true;
840+
return (byte)Keys.Oem7;
841+
case '<':
842+
bShift = true;
843+
return (byte)Keys.Oemcomma;
844+
case '>':
845+
bShift = true;
846+
return (byte)Keys.OemPeriod;
847+
case '?':
848+
bShift = true;
849+
return (byte)Keys.OemQuestion;
850+
}
851+
852+
throw new Exception("Unsupported character: " + cInput);
853+
}
854+
855+
private void ShowKeysNotDefinedError()
856+
{
857+
MessageBox.Show(this, "Please specify both an input and output key.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
858+
}
859+
860+
709861
#endregion
710862

711863
}

Forms/KeyCaptureConfig.designer.cs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

KeyCap.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
<Compile Include="Format\InputConfig.cs" />
5959
<Compile Include="Format\RemapEntry.cs" />
6060
<Compile Include="Settings\KeyCapInstanceState.cs" />
61+
<Compile Include="Support\UI\QueryPanel.cs" />
62+
<Compile Include="Support\UI\QueryPanelDialog.cs" />
6163
<Compile Include="Util\BitUtil.cs" />
6264
<Compile Include="Util\StreamUtil.cs" />
6365
<Compile Include="Forms\KeyCaptureConfig.cs">

KeyCapLib/KeyCapture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////////
22
// The MIT License (MIT)
33
//
4-
// Copyright (c) 2021 Tim Stair
4+
// Copyright (c) 2022 Tim Stair
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal

KeyCapLib/KeyCapture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////////
22
// The MIT License (MIT)
33
//
4-
// Copyright (c) 2021 Tim Stair
4+
// Copyright (c) 2022 Tim Stair
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)