Skip to content

Commit ea5ba7b

Browse files
tekezotekezo
authored and
tekezo
committed
add PressDownKeys
1 parent bd18dbe commit ea5ba7b

File tree

7 files changed

+113
-8
lines changed

7 files changed

+113
-8
lines changed

Diff for: COPYING

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Public Domain

Diff for: src/core/kext/KeyRemap4MacBook.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ org_pqrs_driver_KeyRemap4MacBook::init(OSDictionary *dict)
6565
hookedPointing[i].pointing = NULL;
6666
}
6767
org_pqrs_KeyRemap4MacBook::clickWatcher.reset();
68+
org_pqrs_KeyRemap4MacBook::pressDownKeys.initialize();
6869

6970
KeyRemap4MacBook_client::initialize();
7071

@@ -746,15 +747,15 @@ org_pqrs_driver_KeyRemap4MacBook::keyboardEventCallBack(OSObject *target,
746747
charSet, origCharCode, origCharSet, keyboardType, repeat,
747748
ts, sender, refcon);
748749
org_pqrs_KeyRemap4MacBook::listFireExtraKey.fire(p->origEventCallback, target, charSet, origCharCode, origCharSet, keyboardType, ts, sender, refcon);
749-
750-
// reset modifiers
751-
if (org_pqrs_KeyRemap4MacBook::allFlagStatus.numHeldDownKeys <= 0) {
752-
org_pqrs_KeyRemap4MacBook::RemapUtil::fireModifiers(0, p->origEventCallback, target, keyboardType, ts, sender, refcon);
753-
}
754750
}
755751

756752
p->setExtraRepeatInfo(ex_extraRepeatFunc, ex_extraRepeatFlags, keyboardType, ts, target, refcon);
757753
p->setRepeatInfo(eventType, flags, key, charCode, charSet, origCharCode, origCharSet, keyboardType, ts, target, refcon);
754+
755+
if (org_pqrs_KeyRemap4MacBook::allFlagStatus.numHeldDownKeys <= 0) {
756+
org_pqrs_KeyRemap4MacBook::RemapUtil::fireModifiers(0, p->origEventCallback, target, keyboardType, ts, sender, refcon);
757+
org_pqrs_KeyRemap4MacBook::pressDownKeys.clear(p->origEventCallback, target, ts, sender, refcon);
758+
}
758759
}
759760

760761
void

Diff for: src/core/kext/KeyRemap4MacBook.xcodeproj/project.pbxproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
348ED83A0CE4682000E179EC /* version.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 348ED8390CE4682000E179EC /* version.hpp */; };
2020
348ED8470CE47D9400E179EC /* RemapUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 348ED8460CE47D9400E179EC /* RemapUtil.cpp */; };
2121
348ED8490CE47D9D00E179EC /* RemapUtil.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 348ED8480CE47D9D00E179EC /* RemapUtil.hpp */; };
22+
349581080E7232A5003773EC /* PressDownKeys.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 349581060E7232A5003773EC /* PressDownKeys.cpp */; };
23+
349581090E7232A5003773EC /* PressDownKeys.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 349581070E7232A5003773EC /* PressDownKeys.hpp */; };
2224
34C7A9A20CE45EA400C98397 /* Config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34C7A9A10CE45EA400C98397 /* Config.cpp */; };
2325
34C7A9B00CE4605B00C98397 /* Config.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34C7A9AF0CE4605B00C98397 /* Config.hpp */; };
2426
34FB835F0CE5DBFF00BD6A24 /* base.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34FB835E0CE5DBFF00BD6A24 /* base.hpp */; };
@@ -27,7 +29,7 @@
2729
/* Begin PBXFileReference section */
2830
089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
2931
1A224C3FFF42367911CA2CB7 /* KeyRemap4MacBook.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyRemap4MacBook.cpp; sourceTree = "<group>"; };
30-
32D94FCF0562CBF700B6AF17 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; };
32+
32D94FCF0562CBF700B6AF17 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3133
32D94FD00562CBF700B6AF17 /* KeyRemap4MacBook.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KeyRemap4MacBook.kext; sourceTree = BUILT_PRODUCTS_DIR; };
3234
3452BE010AD6BCAF009D9E15 /* KeyRemap4MacBook.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = KeyRemap4MacBook.hpp; sourceTree = "<group>"; };
3335
345B06AB0DB21A88000023FD /* Client.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Client.cpp; sourceTree = "<group>"; };
@@ -39,6 +41,8 @@
3941
348ED8390CE4682000E179EC /* version.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = version.hpp; sourceTree = "<group>"; };
4042
348ED8460CE47D9400E179EC /* RemapUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemapUtil.cpp; sourceTree = "<group>"; };
4143
348ED8480CE47D9D00E179EC /* RemapUtil.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RemapUtil.hpp; sourceTree = "<group>"; };
44+
349581060E7232A5003773EC /* PressDownKeys.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PressDownKeys.cpp; path = util/PressDownKeys.cpp; sourceTree = "<group>"; };
45+
349581070E7232A5003773EC /* PressDownKeys.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = PressDownKeys.hpp; path = util/PressDownKeys.hpp; sourceTree = "<group>"; };
4246
34C7A9A10CE45EA400C98397 /* Config.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Config.cpp; sourceTree = "<group>"; };
4347
34C7A9AF0CE4605B00C98397 /* Config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Config.hpp; sourceTree = "<group>"; };
4448
34FB835E0CE5DBFF00BD6A24 /* base.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = base.hpp; sourceTree = "<group>"; };
@@ -87,6 +91,8 @@
8791
247142CAFF3F8F9811CA285C /* Source */ = {
8892
isa = PBXGroup;
8993
children = (
94+
349581060E7232A5003773EC /* PressDownKeys.cpp */,
95+
349581070E7232A5003773EC /* PressDownKeys.hpp */,
9096
345B06B70DB21ABF000023FD /* bridge.hpp */,
9197
348ED8350CE4680F00E179EC /* remap.hpp */,
9298
348ED8480CE47D9D00E179EC /* RemapUtil.hpp */,
@@ -121,6 +127,7 @@
121127
34FB835F0CE5DBFF00BD6A24 /* base.hpp in Headers */,
122128
345B06AE0DB21A88000023FD /* Client.hpp in Headers */,
123129
345B06B80DB21ABF000023FD /* bridge.hpp in Headers */,
130+
349581090E7232A5003773EC /* PressDownKeys.hpp in Headers */,
124131
);
125132
runOnlyForDeploymentPostprocessing = 0;
126133
};
@@ -195,6 +202,7 @@
195202
348ED8340CE467FD00E179EC /* remap.cpp in Sources */,
196203
348ED8470CE47D9400E179EC /* RemapUtil.cpp in Sources */,
197204
345B06AD0DB21A88000023FD /* Client.cpp in Sources */,
205+
349581080E7232A5003773EC /* PressDownKeys.cpp in Sources */,
198206
);
199207
runOnlyForDeploymentPostprocessing = 0;
200208
};

Diff for: src/core/kext/RemapUtil.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#include "keycode.hpp"
55
#include "Config.hpp"
66

7+
#include "util/PressDownKeys.hpp"
8+
79
namespace org_pqrs_KeyRemap4MacBook {
810
AllFlagStatus allFlagStatus;
911
ListFireExtraKey listFireExtraKey;
12+
PressDownKeys pressDownKeys;
1013
ListFireConsumerKey listFireConsumerKey;
1114
ListFirePointingClick listFirePointingClick;
1215
FirePointingScroll firePointingScroll;
@@ -434,8 +437,13 @@ namespace org_pqrs_KeyRemap4MacBook {
434437
callback(target, eventType, flags, key, charCode,
435438
charSet, origCharCode, origCharSet, keyboardType, repeat, ts, sender, refcon);
436439

437-
if (key == KeyCode::JIS_EISUU || key == KeyCode::JIS_KANA) {
438-
jisKanaMode.setMode(eventType, key, flags);
440+
if (eventType == KeyEvent::DOWN) {
441+
if (key == KeyCode::JIS_EISUU || key == KeyCode::JIS_KANA) {
442+
jisKanaMode.setMode(eventType, key, flags);
443+
}
444+
pressDownKeys.add(key, keyboardType);
445+
} else {
446+
pressDownKeys.remove(key, keyboardType);
439447
}
440448
}
441449
}

Diff for: src/core/kext/RemapUtil.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <IOKit/hidsystem/IOHIKeyboard.h>
55
#include "remap.hpp"
66
#include "keycode.hpp"
7+
#include "util/PressDownKeys.hpp"
78

89
namespace org_pqrs_KeyRemap4MacBook {
910
namespace RemapUtil {
@@ -501,6 +502,8 @@ namespace org_pqrs_KeyRemap4MacBook {
501502
Mode mode;
502503
};
503504
extern JISKanaMode jisKanaMode;
505+
506+
extern PressDownKeys pressDownKeys;
504507
}
505508

506509
#endif

Diff for: src/core/kext/util/PressDownKeys.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "PressDownKeys.hpp"
2+
#include "RemapUtil.hpp"
3+
#include "keycode.hpp"
4+
5+
namespace org_pqrs_KeyRemap4MacBook {
6+
void
7+
PressDownKeys::initialize(void)
8+
{
9+
for (int i = 0; i < MAXNUM; ++i) {
10+
item[i].enable = false;
11+
}
12+
}
13+
14+
void
15+
PressDownKeys::add(unsigned int _key, unsigned int _keyboardType)
16+
{
17+
for (int i = 0; i < MAXNUM; ++i) {
18+
if (! item[i].enable) {
19+
item[i].enable = true;
20+
item[i].key = _key;
21+
item[i].keyboardType = _keyboardType;
22+
}
23+
}
24+
}
25+
26+
void
27+
PressDownKeys::remove(unsigned int _key, unsigned int _keyboardType)
28+
{
29+
for (int i = 0; i < MAXNUM; ++i) {
30+
if (! item[i].enable) continue;
31+
if (item[i].key != _key) continue;
32+
if (item[i].keyboardType != _keyboardType) continue;
33+
item[i].enable = false;
34+
}
35+
}
36+
37+
void
38+
PressDownKeys::clear(KeyboardEventCallback callback, OSObject *target, AbsoluteTime ts, OSObject *sender, void *refcon)
39+
{
40+
if (callback == NULL) return;
41+
42+
for (int i = 0; i < MAXNUM; ++i) {
43+
if (! item[i].enable) continue;
44+
unsigned int flags = 0;
45+
unsigned int charCode = 0;
46+
unsigned int charSet = 0;
47+
unsigned int origCharCode = 0;
48+
unsigned int origCharSet = 0;
49+
RemapUtil::fireKey(callback,
50+
target, KeyEvent::UP, flags, item[i].key,
51+
charCode, charSet, origCharCode, origCharSet,
52+
item[i].keyboardType, false, ts, sender, refcon);
53+
}
54+
}
55+
}

Diff for: src/core/kext/util/PressDownKeys.hpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef REMAPUTIL_PRESSDOWNKEYS_HPP
2+
#define REMAPUTIL_PRESSDOWNKEYS_HPP
3+
4+
#include "base.hpp"
5+
6+
namespace org_pqrs_KeyRemap4MacBook {
7+
// ----------------------------------------------------------------------
8+
// store RemapUtil::fireKey results
9+
class PressDownKeys {
10+
public:
11+
void initialize(void);
12+
void add(unsigned int _key, unsigned int _keyboardType);
13+
void remove(unsigned int _key, unsigned int _keyboardType);
14+
void clear(KeyboardEventCallback callback, OSObject *target, AbsoluteTime ts, OSObject *sender, void *refcon);
15+
16+
private:
17+
enum {
18+
MAXNUM = 16,
19+
};
20+
struct Item {
21+
bool enable;
22+
unsigned int key;
23+
unsigned int keyboardType;
24+
};
25+
Item item[MAXNUM];
26+
};
27+
}
28+
29+
#endif

0 commit comments

Comments
 (0)