11using AutoHotInterception . Helpers ;
22using System ;
33using System . Collections . Concurrent ;
4+ using System . Collections . Generic ;
45using System . Threading ;
56
67namespace AutoHotInterception . DeviceHandlers
@@ -34,25 +35,18 @@ public override void DisableFilterIfNeeded()
3435 /// <param name="state">The State to send (1 = pressed, 0 = released)</param>
3536 public void SendKeyEvent ( ushort code , int state )
3637 {
37- var st = 1 - state ;
38- var stroke = new ManagedWrapper . Stroke ( ) ;
39- if ( code > 255 )
38+ var strokes = ScanCodeHelper . TranslateAhkCode ( code , state ) ;
39+ for ( int i = 0 ; i < strokes . Count ; i ++ )
4040 {
41- code -= 256 ;
42- if ( code != 54 ) // RShift has > 256 code, but state is 0/1
43- st += 2 ;
41+ var stroke = strokes [ i ] ;
42+ ManagedWrapper . Send ( DeviceContext , DeviceId , ref stroke , 1 ) ;
4443 }
45-
46- stroke . key . code = code ;
47- stroke . key . state = ( ushort ) st ;
48- ManagedWrapper . Send ( DeviceContext , DeviceId , ref stroke , 1 ) ;
4944 }
5045 #endregion
5146
5247 // ScanCode notes: https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
53- public override void ProcessStroke ( ManagedWrapper . Stroke stroke )
48+ public override void ProcessStroke ( List < ManagedWrapper . Stroke > strokes )
5449 {
55- //ManagedWrapper.Send(DeviceContext, _deviceId, ref stroke, 1);
5650 var hasSubscription = false ;
5751 var hasContext = ContextCallback != null ;
5852
@@ -62,7 +56,7 @@ public override void ProcessStroke(ManagedWrapper.Stroke stroke)
6256 if ( _isFiltered )
6357 {
6458 var isKeyMapping = false ; // True if this is a mapping to a single key, else it would be a mapping to a whole device
65- var processedState = HelperFunctions . KeyboardStrokeToKeyboardState ( stroke ) ;
59+ var processedState = ScanCodeHelper . TranslateScanCodes ( strokes ) ;
6660 var code = processedState . Code ;
6761 var state = processedState . State ;
6862 MappingOptions mapping = null ;
@@ -81,41 +75,30 @@ public override void ProcessStroke(ManagedWrapper.Stroke stroke)
8175
8276 if ( mapping != null )
8377 {
84- // Begin translation of incoming key code, state, extended flag etc...
85- var processMappings = true ;
86- if ( processedState . Ignore )
78+ hasSubscription = true ;
79+
80+ if ( mapping . Block ) block = true ;
81+ if ( mapping . Concurrent )
8782 {
88- // Set flag to stop Context Mode from firing
89- hasSubscription = true ;
90- // Set flag to indicate disable mapping processing
91- processMappings = false ;
83+ if ( isKeyMapping )
84+ {
85+ ThreadPool . QueueUserWorkItem ( threadProc => mapping . Callback ( state ) ) ;
86+ }
87+ else
88+ {
89+ ThreadPool . QueueUserWorkItem ( threadProc => mapping . Callback ( code , state ) ) ;
90+ }
9291 }
93- if ( processMappings )
92+ else
9493 {
95- hasSubscription = true ;
96-
97- if ( mapping . Block ) block = true ;
98- if ( mapping . Concurrent )
94+ //mapping.Callback(code, state);
95+ if ( isKeyMapping )
9996 {
100- if ( isKeyMapping )
101- {
102- ThreadPool . QueueUserWorkItem ( threadProc => mapping . Callback ( state ) ) ;
103- }
104- else
105- {
106- ThreadPool . QueueUserWorkItem ( threadProc => mapping . Callback ( code , state ) ) ;
107- }
97+ WorkerThreads [ code ] ? . Actions . Add ( ( ) => mapping . Callback ( state ) ) ;
10898 }
10999 else
110100 {
111- if ( isKeyMapping )
112- {
113- WorkerThreads [ code ] ? . Actions . Add ( ( ) => mapping . Callback ( state ) ) ;
114- }
115- else
116- {
117- DeviceWorkerThread ? . Actions . Add ( ( ) => mapping . Callback ( code , state ) ) ;
118- }
101+ DeviceWorkerThread ? . Actions . Add ( ( ) => mapping . Callback ( code , state ) ) ;
119102 }
120103 }
121104
@@ -127,8 +110,12 @@ public override void ProcessStroke(ManagedWrapper.Stroke stroke)
127110 // ... then set the Context before sending the key
128111 if ( ! hasSubscription && hasContext ) ContextCallback ( 1 ) ;
129112
130- // Pass the key through to the OS.
131- ManagedWrapper . Send ( DeviceContext , DeviceId , ref stroke , 1 ) ;
113+ // Pass the key(s) through to the OS.
114+ for ( int i = 0 ; i < strokes . Count ; i ++ )
115+ {
116+ var stroke = strokes [ i ] ;
117+ ManagedWrapper . Send ( DeviceContext , DeviceId , ref stroke , 1 ) ;
118+ }
132119
133120 // If we are processing Context Mode, then Unset the context variable after sending the key
134121 if ( ! hasSubscription && hasContext ) ContextCallback ( 0 ) ;
0 commit comments