Skip to content

Commit 927cc3b

Browse files
committed
Added repeat functionality (hard coded to 100ms delay).
1 parent e5d4852 commit 927cc3b

17 files changed

+156
-81
lines changed

Format/OutputConfig.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public enum OutputFlag
5454
Toggle = 1 << 6,
5555
Down = 1 << 7,
5656
Up = 1 << 8,
57+
Repeat = 1 << 9,
5758
// all ThreadKill ?
5859
// supports up to 32 entries
5960
}
@@ -146,7 +147,7 @@ public bool IsAssignedAction()
146147
private string GetOutputDescriptionText(Enum eInputId, string sActionPrefix)
147148
{
148149
return "[" +
149-
(Keys)VirtualKey +
150+
eInputId +
150151
(IsFlaggedAs(OutputFlag.Down) && IsFlaggedAs(OutputFlag.Up)
151152
? ":Press"
152153
: ((IsFlaggedAs(OutputFlag.Down) ? ":{0}Down".FormatString(sActionPrefix) : string.Empty) +
@@ -156,6 +157,7 @@ private string GetOutputDescriptionText(Enum eInputId, string sActionPrefix)
156157
(IsFlaggedAs(OutputFlag.Alt) ? "+Alt" : string.Empty) +
157158
(IsFlaggedAs(OutputFlag.Control) ? "+Control" : string.Empty) +
158159
(IsFlaggedAs(OutputFlag.Toggle) ? "+Toggle" : string.Empty) +
160+
(IsFlaggedAs(OutputFlag.Repeat) ? "+Repeat" : string.Empty) +
159161
"]";
160162
}
161163
}

Format/RemapEntry.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ public RemapEntry(FileStream zFileStream)
7272
}
7373

7474
// TODO: comment on why this is
75-
zFileStream.ReadByte();
76-
zFileStream.ReadByte();
77-
zFileStream.ReadByte();
75+
zFileStream.Read(new byte[3], 0, 3);
7876

7977
try
8078
{
@@ -107,9 +105,7 @@ public byte[] SerializeToBytes()
107105
InputConfig.SerializeToStream(zStream);
108106
zStream.WriteByte((byte)OutputConfigs.Count);
109107
// TODO: comment on padding
110-
zStream.WriteByte(0);
111-
zStream.WriteByte(0);
112-
zStream.WriteByte(0);
108+
zStream.Write(new byte[3], 0, 3);
113109
OutputConfigs.ForEach(oc => oc.SerializeToStream(zStream));
114110
return zStream.ToArray();
115111
}

Forms/KeyCaptureConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ private OutputConfig UpdateOutputFlags(OutputConfig zOutputConfig)
498498
var bShift = checkOutputShift.Checked;
499499
var bNone = checkOutputDoNothing.Checked;
500500
var bToggle = checkOutputToggle.Checked;
501+
var bRepeat = checkOutputRepeat.Checked;
501502
var bDown = checkOutputDown.Checked;
502503
var bUp = checkOutputUp.Checked;
503504

@@ -510,6 +511,7 @@ private OutputConfig UpdateOutputFlags(OutputConfig zOutputConfig)
510511

511512
nFlags = BitUtil.UpdateFlag(nFlags, bNone, OutputConfig.OutputFlag.DoNothing);
512513
nFlags = BitUtil.UpdateFlag(nFlags, bToggle, OutputConfig.OutputFlag.Toggle);
514+
nFlags = BitUtil.UpdateFlag(nFlags, bRepeat, OutputConfig.OutputFlag.Repeat);
513515
nFlags = BitUtil.UpdateFlag(nFlags, bDown, OutputConfig.OutputFlag.Down);
514516
nFlags = BitUtil.UpdateFlag(nFlags, bUp, OutputConfig.OutputFlag.Up);
515517
zOutputConfig.Flags = nFlags;

Forms/KeyCaptureConfig.designer.cs

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

KeyCapLib/KeyCapture.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern "C"
4242
HHOOK g_hookMain = NULL;
4343

4444
// sweet globals
45-
RemapEntryListItem* g_KeyTranslationTable[WIN_KEY_COUNT];
45+
RemapEntryContainerListItem* g_KeyTranslationTable[WIN_KEY_COUNT];
4646
RemapEntry* g_KeyTranslationHead = NULL;
4747
void* g_KeyTranslationEnd = NULL; // pointer indicating the end of the input file data
4848

@@ -69,7 +69,7 @@ __declspec(dllexport) int LoadAndCaptureFromFile(HINSTANCE hInstance, char* sFil
6969
}
7070

7171
// validate file (and compile the "hash" table g_KeyTranslationTable)
72-
memset(g_KeyTranslationTable, 0, WIN_KEY_COUNT * sizeof(RemapEntryListItem*));
72+
memset(g_KeyTranslationTable, 0, WIN_KEY_COUNT * sizeof(RemapEntryContainerListItem*));
7373

7474
RemapEntry* pEntry = g_KeyTranslationHead;
7575
bool bValidTranslationSet = false;
@@ -91,21 +91,25 @@ __declspec(dllexport) int LoadAndCaptureFromFile(HINSTANCE hInstance, char* sFil
9191
// if the entry doesn't exist yet for the given input vkey create a new one with a null next pointer
9292
if(NULL == g_KeyTranslationTable[pEntry->inputConfig.virtualKey])
9393
{
94-
g_KeyTranslationTable[pEntry->inputConfig.virtualKey] = (RemapEntryListItem*)malloc(sizeof(RemapEntryListItem));
95-
g_KeyTranslationTable[pEntry->inputConfig.virtualKey]->pEntry = pEntry;
94+
g_KeyTranslationTable[pEntry->inputConfig.virtualKey] = (RemapEntryContainerListItem*)malloc(sizeof(RemapEntryContainerListItem));
95+
g_KeyTranslationTable[pEntry->inputConfig.virtualKey]->pEntryContainer = (RemapEntryContainer*)malloc(sizeof(RemapEntryContainer));
96+
g_KeyTranslationTable[pEntry->inputConfig.virtualKey]->pEntryContainer->pEntryState = (RemapEntryState*)malloc(sizeof(RemapEntryState));
97+
g_KeyTranslationTable[pEntry->inputConfig.virtualKey]->pEntryContainer->pEntry = pEntry;
9698
g_KeyTranslationTable[pEntry->inputConfig.virtualKey]->pNext = NULL;
9799
}
98100
// if the entry does exist create a new entry and append it to the existing linked list
99101
else
100102
{
101-
RemapEntryListItem* pKeyItem = g_KeyTranslationTable[pEntry->inputConfig.virtualKey];
103+
RemapEntryContainerListItem* pKeyItem = g_KeyTranslationTable[pEntry->inputConfig.virtualKey];
102104
while(NULL != pKeyItem->pNext)
103105
{
104106
pKeyItem = pKeyItem->pNext;
105107
}
106-
pKeyItem->pNext = (RemapEntryListItem*)malloc(sizeof(RemapEntryListItem));
108+
pKeyItem->pNext = (RemapEntryContainerListItem*)malloc(sizeof(RemapEntryContainerListItem));
107109
pKeyItem = pKeyItem->pNext;
108-
pKeyItem->pEntry = pEntry;
110+
pKeyItem->pEntryContainer = (RemapEntryContainer*)malloc(sizeof(RemapEntryContainer));
111+
pKeyItem->pEntryContainer->pEntryState = (RemapEntryState*)malloc(sizeof(RemapEntryState));
112+
pKeyItem->pEntryContainer->pEntry = pEntry;
109113
pKeyItem->pNext = NULL;
110114
}
111115
// jump to the next entry
@@ -170,13 +174,16 @@ __declspec(dllexport) void ShutdownCapture()
170174
{
171175
if(NULL != g_KeyTranslationTable[nIdx])
172176
{
173-
RemapEntryListItem* pKeyItem = g_KeyTranslationTable[nIdx];
174-
RemapEntryListItem* pKeyNextItem = NULL;
175-
while(NULL != pKeyItem)
177+
RemapEntryContainerListItem* pListItem = g_KeyTranslationTable[nIdx];
178+
RemapEntryContainerListItem* pNextItem = NULL;
179+
while(NULL != pListItem)
176180
{
177-
pKeyNextItem = pKeyItem->pNext;
178-
free(pKeyItem);
179-
pKeyItem = pKeyNextItem;
181+
pNextItem = pListItem->pNext;
182+
free(pListItem->pEntryContainer->pEntryState);
183+
free(pListItem->pEntryContainer);
184+
// NOTE: the entry itself was freed above
185+
free(pListItem);
186+
pListItem = pNextItem;
180187
}
181188
g_KeyTranslationTable[nIdx] = NULL;
182189
}

KeyCapLib/KeyCaptureUtil.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@
2525
#include "keycapturestructs.h"
2626
#include "keycaptureutil.h"
2727

28-
bool IsButtonDownRequired(RemapEntry* pRemapEntry, OutputConfig* pKeyDef)
28+
bool IsButtonDownRequired(RemapEntryState* pRemapEntryState, OutputConfig* pKeyDef)
2929
{
3030
if (pKeyDef->outputFlag.bToggle)
3131
{
32-
return !pRemapEntry->bToggled;
32+
return !pRemapEntryState->bToggled;
3333
}
3434

3535
bool keyDownRequired = true;
3636
keyDownRequired = pKeyDef->outputFlag.bDown;
3737
return keyDownRequired;
3838
}
3939

40-
bool IsButtonUpRequired(RemapEntry* pRemapEntry, OutputConfig* pKeyDef)
40+
bool IsButtonUpRequired(RemapEntryState* pRemapEntryState, OutputConfig* pKeyDef)
4141
{
4242
if (pKeyDef->outputFlag.bToggle)
4343
{
44-
return pRemapEntry->bToggled;
44+
return pRemapEntryState->bToggled;
4545
}
4646

4747
bool keyUpRequired = true;

KeyCapLib/KeyCaptureUtil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
const int DESCRIPTION_BUFFER_SIZE = 256;
3232

33-
bool IsButtonDownRequired(RemapEntry* pRemapEntry, OutputConfig* pKeyDef);
34-
bool IsButtonUpRequired(RemapEntry* pRemapEntry, OutputConfig* pKeyDef);
33+
bool IsButtonDownRequired(RemapEntryState* pRemapEntryState, OutputConfig* pKeyDef);
34+
bool IsButtonUpRequired(RemapEntryState* pRemapEntryState, OutputConfig* pKeyDef);
3535

3636
void LogDebugMessage(const char *format, ...);
3737
void ValidateStructs();

KeyCapLib/KeyboardInput.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,14 @@ pKeyDef: pointer to a key definition for a keyboard input to send
8888
pTriggerDefinition: The definition of the triggering key. Modifiers like shift/alt/ctrl require special handling under
8989
certain circumstances
9090
*/
91-
void SendInputKeys(RemapEntry* pRemapEntry, OutputConfig* pKeyDef)
91+
void SendInputKeys(RemapEntryState* pRemapEntryState, OutputConfig* pKeyDef)
9292
{
9393
int nIndex = 0;
94-
bool bSendKeyDown = IsButtonDownRequired(pRemapEntry, pKeyDef);
95-
bool bSendKeyUp = IsButtonUpRequired(pRemapEntry, pKeyDef);
94+
bool bSendKeyDown = IsButtonDownRequired(pRemapEntryState, pKeyDef);
95+
bool bSendKeyUp = IsButtonUpRequired(pRemapEntryState, pKeyDef);
9696
INPUT inputBuffer[MAX_KEY_INPUT_PER_STROKE];
9797
memset(&inputBuffer, 0, sizeof(INPUT) * MAX_KEY_INPUT_PER_STROKE);
9898

99-
LogDebugMessage("%d", pKeyDef->outputFlag);
100-
10199
if (pKeyDef->outputFlag.bToggle && pKeyDef->virtualKey >= MAX_VKEY)
102100
{
103101
LogDebugMessage("---- ERROR Cannot have a vkey value over 255: %d", pKeyDef->virtualKey);

KeyCapLib/KeyboardInput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include "keycapturestructs.h"
2929

30-
void SendInputKeys(RemapEntry* pRemapEntry, OutputConfig* pKeyDef);
30+
void SendInputKeys(RemapEntryState* pRemapEntryState, OutputConfig* pKeyDef);
3131
void SendTriggerEndInputKeys(RemapEntry* pRemapEntry);
3232
void AppendSingleKey(short keyScan, INPUT* inputChar, DWORD dwFlags);
3333
void ProcessModifierKeys(OutputConfig* pKeyDef, INPUT* pInput, int* nIndex, DWORD dwFlags);

KeyCapLib/MouseInput.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ Sends the desired mouse input
3636
3737
pKeyDef: pointer to a key definition for a mouse input
3838
*/
39-
void SendInputMouse(RemapEntry* pRemapEntry, OutputConfig *pKeyDef)
39+
void SendInputMouse(RemapEntryState* pRemapEntryState, OutputConfig *pKeyDef)
4040
{
4141
INPUT inputBuffer[MAX_KEY_INPUT_PER_STROKE];
4242
memset(&inputBuffer, 0, sizeof(INPUT) * MAX_KEY_INPUT_PER_STROKE);
4343

44-
bool bSendMouseDown = IsButtonDownRequired(pRemapEntry, pKeyDef);
45-
bool bSendMouseUp = IsButtonUpRequired(pRemapEntry, pKeyDef);
44+
bool bSendMouseDown = IsButtonDownRequired(pRemapEntryState, pKeyDef);
45+
bool bSendMouseUp = IsButtonUpRequired(pRemapEntryState, pKeyDef);
4646

4747
if (pKeyDef->virtualKey == MOUSE_NONE)
4848
{

0 commit comments

Comments
 (0)