-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyHandling.cpp
More file actions
88 lines (74 loc) · 2.54 KB
/
KeyHandling.cpp
File metadata and controls
88 lines (74 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Open source not for commercial deployment
*/
//---------------------------------------------------------------------------
#pragma hdrstop
#include "KeyHandling.h"
String KeyfileBaseDir;
KeyHandling::KeyHandling()
{
shiftDown = false;
controlDown = false;
altDown = false;
inputData = "";
showKey = true;
}
String KeyHandling::ProcessKeyDown(WORD &Key, TShiftState Shift)
{
String tmp = "";
if (Shift.Contains(ssAlt)) { altDown = true; tmp = "1"+tmp; } else { altDown = false; tmp = "0"+tmp; }
if (Shift.Contains(ssShift)) { shiftDown = true; tmp = "1"+tmp; } else { shiftDown = false; tmp = "0"+tmp; }
if (Shift.Contains(ssCtrl)) { controlDown = true; tmp = "1"+tmp; } else { controlDown = false; tmp = "0"+tmp; }
Log("Key pressed: " + tmp + "," + Key);
return ProcessKeyDown(Key);
}
String KeyHandling::ProcessKeyDown(WORD Key)
{
int KeyNumber = Key&0xFF;
if (altDown) KeyNumber+=256;
if (shiftDown) KeyNumber+=512;
if (controlDown) KeyNumber+=1024;
return KeyCommand[KeyNumber];
}
void KeyHandling::ProcessKeyUp(WORD &Key, TShiftState Shift)
{
shiftDown = Shift.Contains(ssShift);
controlDown = Shift.Contains(ssCtrl);
altDown = Shift.Contains(ssAlt);
}
void KeyHandling::LoadKeySettingsFile(String fileName)
{
if (fileName.Pos(":")==0)
fileName = KeyfileBaseDir + fileName;
ifstream keyFile (fileName.c_str());
if (! keyFile.is_open())
{
MessageDlg("Could not load the key file: "+ fileName, mtInformation, TMsgDlgButtons()<<mbOK , 0);
return;
}
char buffer[1024];
while (!keyFile.eof())
{
keyFile.getline(buffer,1024);
String temp = buffer;
if ( (temp.Length()>7) && (temp[4]==',') && (temp[8]==',') )
{
int C = StrToInt(temp.SubString(1,1));
int S = StrToInt(temp.SubString(2,1));
int A = StrToInt(temp.SubString(3,1));
int KeyNr = StrToInt(temp.SubString(5,3));
if ((KeyNr>255) || (C>1) || (S>1) || (A>1))
{
MessageDlg("Error in keyfile key value to high max: (111,255) :"+temp, mtInformation, TMsgDlgButtons()<<mbOK , 0);
}
KeyCommand[(A*256)+(S*512)+(C*1024) + KeyNr]=temp.SubString(9,temp.Length()-8);
}
}
keyFile.close();
}
void KeyHandling::setBaseDir( String BaseDir)
{
KeyfileBaseDir = BaseDir + "Settings\\";
}
//---------------------------------------------------------------------------
#pragma package(smart_init)