Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only target a specific keyboard type/model for remapping #3

Closed
tveyben opened this issue Jul 28, 2020 · 12 comments
Closed

Only target a specific keyboard type/model for remapping #3

tveyben opened this issue Jul 28, 2020 · 12 comments

Comments

@tveyben
Copy link

tveyben commented Jul 28, 2020

I am not able to find the description of how to only target a specific keyboard-model with the remappings.

Is this possible (what have I overlooked in the documentation)?

Use case
My use case is that I have not been able to find a keyboard with the same (or better) mechanical feel as the Apple keyboard (USB with numeric keys) with a Windows keyboard-layout to be used for my Windows/Linux PC's, hence I thought I could "just" remap the keys and re-label the Apple keyboard resulting in (EG ALT->WIN, CMD-> ALT etc).

As I am using a labtop, I only need the remapping when I am using the PC in my docking station (with the Apple keyboard attached), when I am using the built-in keyboard I need the not-remapped functionality.

Background:
I originally found this project (https://www.orbiter-forum.com/showthread.php?t=30829 using the same interception driver) but am unable to make it work on Win10 due to missing MSVCP100.dll & MSVCR100.dll (no matter which Microsoft Visual C++ 2010 Redistributable I install I don't get the DLL's, (thank you Microsoft...!).

Then I found your project - looks capable of a lot more!

@cajhin
Copy link
Owner

cajhin commented Jul 28, 2020

Hi

Device-specific mappings are not configurable in the .ini (yet? I almost did it but I don't need it).

BUT good news:
There is hardcoded Apple keyboard detection, that should detect all Apple keyboards (works for my old MacBook. and my old wired and wireless Apple keyboards).

If you enable "hardcoded Apple mapping"

  1. CMD (Win) and ALT are flipped on Apple keyboards
  2. Other keyboards work as usual
  3. You can move between Laptop(PC) board and external(Apple) board on the fly, Capsicain only flips it on the Apple board
  4. Enable it with "OPTION FlipAltWinOnAppleKeyboards" in your capsicain.ini

If this is all you want, you basically need to have an almost empty .ini with only this:
GLOBAL ActiveLayerOnStartup 1
[LAYER1]
OPTION FlipAltWinOnAppleKeyboards

(haven't tried it out, maybe I forgot a mandatory setting).

Note:
you can turn the "Apple feature" on and off with [ESC]+W (W like "Win key"),
even without anything in your ini. But then you have to remember to do this after every boot, so .ini is better.

@tveyben
Copy link
Author

tveyben commented Jul 28, 2020

Excellent and quick feedback - 1E3 thanks! That's a large part of what I am after.

You might want to add to the README that in case you get an error message about missing DLL's (MSVCP140 & VCRUNTIME140.dll) you then need to install the latest Microsoft Visual C++ Redistributable Package
I had to install this vc_redist.x64.exe

I see that there could be made small improvements since - at least - F13 - F19 are not being used.
They could probably be very useful if F13-F15 could be re-mapped to these three missing keys: PRINT_SCRN/SYSRQ, SCROLL_LOCK & PAUSE/BREAK

F-13-F-19 get reported like this (using your debug feature):

getHardwareId:HID\VID_05AC&PID_0250&REV_0074&MI_00 / Apple keyboard: 1
new keyboard: Apple keyboard    --> SEQUENCE (0)
 [F13v =64 0] [M:0]      (16 ms)        -- {F13v}        (1 ms)
 [F13^ =64 1] [M:0]      (6 ms) -- {F13^}        (1 ms)
 [F14v =65 0] [M:0]      (6 ms) -- {F14v}        (1 ms)
 [F14^ =65 1] [M:0]      (6 ms) -- {F14^}        (1 ms)
 [F15v =66 0] [M:0]      (7 ms) -- {F15v}        (1 ms)
 [F15^ =66 1] [M:0]      (6 ms) -- {F15^}        (1 ms)
 [v =67 0] [M:0]         (6 ms) -- {v}   (1 ms)
 [^ =67 1] [M:0]         (7 ms) -- {^}   (1 ms)
 [v =68 0] [M:0]         (6 ms) -- {v}   (1 ms)
 [^ =68 1] [M:0]         (7 ms) -- {^}   (1 ms)
 [v =69 0] [M:0]         (6 ms) -- {v}   (1 ms)
 [^ =69 1] [M:0]         (6 ms) -- {^}   (1 ms)
 [v =6a 0] [M:0]         (6 ms) -- {v}   (1 ms)
 [^ =6a 1] [M:0]         (7 ms) -- {^}   (1 ms)

I will play some more and see if I can identify suggestions for F16-F19.

NB.: Is it possible to let this run as a service (aka a "faceless" application) in stead of having a window present...?

@cajhin
Copy link
Owner

cajhin commented Jul 28, 2020

Thanks for the feedback. I should include the DLLs (I hate it when I have to install that stuff manually; I'm a big fan of self-contained software packages).

F16-F19 are simply not given any 'labels'. I thought those keys died after 1970's IBM keyboards and saved the 3 minutes...

The following, when in your [LAYER1] section, does a "hard rewire" of F13/14/15, that is, it really replaces the scancodes before any modifiers are evaluated:
REWIRE F13 SYSRQ #[Print]
REWIRE F14 SCRLOCK #[ScrollLock]
REWIRE F15 PAUSE #[Pause]

If you wanted to do it with a combo (like LeftAlt+F15 -> Pause)
but keep the F15 key, you would define this instead:
COMBO F15 [&...] > key(PAUSE)

"Run headless?"
You can create a shortcut and set "Run: Minimized" then you never see the window;
but the icon in the taskbar is always there. I don't like 'invisible' apps.
Could make a traybar icon instead (that's a very joyless coding task though...)

@tveyben
Copy link
Author

tveyben commented Jul 28, 2020

REWIRE F13 SYSRQ #[Print] Great!, but it have no effect (I validated that I'm indeed using my latest config version by bumping the GLOBAL IniVersion.

I was also a little surprised by the F16-> keys, I presume Apple added them to make the keyboard look nice (and hey - you get four extra keys to play with :-) Truth being I have not used them in my many years with these keyboards...

A traybar icon is much preferable (for me at least) compared to an extra window even though that might get started minimized (that would just be one more thing to ALT+TAB through when working. The window is great for debugging. So if a traybar could hide and show the current window that would be awesome!

It's unfortunate that the coding of this specific functionality don't pay back as being "fun", but I hope you see the value (I for one do...)

Anyway first I need to get F13-F15 working.
Here's my complete config:

GLOBAL IniVersion 7

GLOBAL ActiveLayerOnStartup 1
GLOBAL DebugOnStartup

[LAYER_1]
OPTION layerName TvE-01
OPTION FlipAltWinOnAppleKeyboards

#[Print]
REWIRE F13 SYSRQ 	

#[ScrollLock]
REWIRE F14 SCRLOCK 	

#[Pause]
REWIRE F15 PAUSE 	

[LAYER_2]
OPTION layerName TvE-02

[LAYER_9]
OPTION LayerName Test
OPTION debug

@cajhin
Copy link
Owner

cajhin commented Jul 29, 2020

Your ini is technically correct and it works for me (I had to substitute F13-15 with F3-5, and using a non-apple board).
Does the log show the keys with no translation? (like "F13v ..... -- F13v")
If so, remove the comment with brackets # [Print] just to make sure there is no bug where it sees [Print] as a section. I really don't think there's a bug but well, you say the .ini does not work for you...

@tveyben
Copy link
Author

tveyben commented Jul 29, 2020

I had some problems trying to copy the debug output yesterday, all keyboardevents were ignored (in some cases buffered for many seconds / appeared stalled), I had to kill and restart capsicain to regain control and then my (apparently not) copied log was not to be found in the clipboard, hence no log...

Today I'm not facing these problems (yet) :-) thus can provide a complete log.
I trimmed down the ini file by removing trailing whitespace, tabs and all comments, bumped IniVersion, reset (ESC+R) and retested.

  • Both keyboards (Apple and Lenovo labtop) do not change F3's behavior
  • Apple keyboard F14+F15 also is unaffected

The ini file

GLOBAL IniVersion 10
GLOBAL ActiveLayerOnStartup 1
GLOBAL DebugOnStartup

[LAYER_1]
OPTION layerName TvE-01
OPTION debug
REWIRE F3 SYSRQ
REWIRE F14 SCRLOCK
REWIRE F15 PAUSE
OPTION FlipAltWinOnAppleKeyboards

The debug log

::RESET --> SEQUENCE (0)
Resetting all modifiers to UP
        --> SEQUENCE (11) {LSHF^} {RSHF^} {LCTRL^} {RCTRL^} {LWIN^} {RWIN^} {LALT^} {RALT^} {CAPS^} {F14^} {F15^}
Assembled config for Layer 1 : 6 lines
No ini setting for 'option delayForKeySequenceMS'. Using default 5
Mod   Definitions: 0
Combo Definitions: 0
Alpha Definitions: 0
ACTIVE LAYER: (1) tve-01
getHardwareId:ACPI\VEN_LEN&DEV_0071 / Apple keyboard: 0
PC keyboard
 [R^ =13 1] [M:0]        (8 ms) -- >(blocked R UP: was not down)>        (0 ms)

::STATUS

Capsicain version: 46
ini version: 10
hardware id:ACPI\VEN_LEN&DEV_0071
Apple keyboard: 0
active layer: (1) tve-01
modifier state: 0
delay between keys in sequences (ms): 5
number of keys-down sent: 0
clean error log (0 chars)

 [S^ =1f 1] [M:0]        (5 ms) -- >(blocked S UP: was not down)>        (1 ms)
getHardwareId:HID\VID_05AC&PID_0250&REV_0074&MI_00 / Apple keyboard: 1
new keyboard: Apple keyboard    --> SEQUENCE (0)
 [F3v =3d 0] [M:0]       (14 ms)        -- {F3v}         (1 ms)
 [F3^ =3d 1] [M:0]       (7 ms) -- {F3^}         (1 ms)
 [F13v =64 0] [M:0]      (7 ms) -- {F13v}        (1 ms)
 [F13^ =64 1] [M:0]      (8 ms) -- {F13^}        (1 ms)
 [F14v =65 0] [M:0]      (7 ms) -- {F14v}        (1 ms)
 [F14^ =65 1] [M:0]      (9 ms) -- {F14^}        (1 ms)
 [F15v =66 0] [M:0]      (7 ms) -- {F15v}        (1 ms)
 [F15^ =66 1] [M:0]      (6 ms) -- {F15^}        (1 ms)
getHardwareId:ACPI\VEN_LEN&DEV_0071 / Apple keyboard: 0
new keyboard: IBM keyboard      --> SEQUENCE (0)
 [F3v =3d 0] [M:0]       (13 ms)        -- {F3v}         (1 ms)
 [F3^ =3d 1] [M:0]       (6 ms) -- {F3^}         (1 ms)

PS.: Not a problem, but an observation: I can see that you're reporting the active layer with the name converted to lower case (TvE-01 => tve-01)

@tveyben
Copy link
Author

tveyben commented Jul 29, 2020

Ha! - I found a workaround :-)

My main missing feature was print screen & alt+print screen (to take screenshots of the whole screen / the active window).

I managed to identify this workaround:

# F13 to Print Screen/SysRq
# F14 to Scroll Lock
# F15 to Pause/Break

ALPHA_FROM F13    F14      F15
ALPHA_TO   SYSRQ  SCRLOCK  PAUSE
ALPHA_END

Once in a while I like to use WIN+BREAK to show the system information window, but that I am still playing with.

PS.: In case you choose to make a traybar icon, I'd like to suggest that part of the icon will reveal which of the 9 layers that's currently active by showing that number on top of the icon (I'm sure we can find an image of a Chili that could be used...)

@cajhin
Copy link
Owner

cajhin commented Jul 30, 2020

Your issue yesterday with the dead keyboard when copying the debug output is a feature of Windows Console apps (including cmd.exe). When you make a selection, the underlying process is paused, so that the text is not updated while you select.
When you've made your copy you MUST click into the console to deselect, then the process continues.

Your workaround works; but for your usecase, a REWIRE is nicer. Basically the keypresses are processed in three stages 1. REWIRE 2. COMBOs 3. Alphamaps. If you use alphamaps, you're a bit limited when you want to define crazy combos on your F13 key.

I'm a bit unhappy that this does not work.
I've used it myself a lot, for a long time, on 5 PCs and a dozen keyboards, never an issue. I'd like to troubleshoot this.
Could you please try it with basic keys, like switch [1] and [2]:
REWIRE 1 2
REWIRE 2 1
And try the same with any other keyboard (not your special Apple one)

(btw a traybar icon showing the active layer is a nice idea. Although I've settled on a configuration, I never switch anymore. Visiting colleagues get a 2nd keyboard that is not processed).

@tveyben
Copy link
Author

tveyben commented Jul 30, 2020

Of course I'll help to debug!

I have created LAYER_2 only with debug + the suggested rewire.
As you can see from the below log, it still appears non functional.

Three keyboards have been used for this test - all with the same result:

  • The labtop's built-in keyboard (Lenovo L450)
  • An HP keyboard
  • The Apple (USB w/numeric keys)
[::RESET --> SEQUENCE (0)
Resetting all modifiers to UP
        --> SEQUENCE (11) {LSHF^} {RSHF^} {LCTRL^} {RCTRL^} {LWIN^} {RWIN^} {LALT^} {RALT^} {CAPS^} {F14^} {F15^}
Assembled config for Layer 1 : 6 lines
No ini setting for 'option delayForKeySequenceMS'. Using default 5
Mod   Definitions: 0
Combo Definitions: 1
Alpha Definitions: 3
ACTIVE LAYER: (1) tve-01
getHardwareId:ACPI\VEN_LEN&DEV_0071 / Apple keyboard: 0
PC keyboard
 [R^ =13 1] [M:0]        (1 ms) -- >(blocked R UP: was not down)>        (0 ms)

::LAYER CHANGE: 2
Assembled config for Layer 2 : 4 lines
No ini setting for 'option delayForKeySequenceMS'. Using default 5
Mod   Definitions: 0
Combo Definitions: 1
Alpha Definitions: 0
ACTIVE LAYER: (2) tve-02
 [2^ =3 1] [M:0]         (3 ms) -- >(blocked 2 UP: was not down)>        (0 ms)

::INI filtered for layer (2) tve-02
option layername tve-02
option debug
rewire 1 2
rewire 2 1
 [I^ =17 1] [M:0]        (3 ms) -- >(blocked I UP: was not down)>        (0 ms)
 [1v =2 0] [M:0]         (2 ms) -- {1v}  (0 ms)
 [1^ =2 1] [M:0]         (2 ms) -- {1^}  (0 ms)
 [2v =3 0] [M:0]         (7 ms) -- {2v}  (1 ms)
 [2^ =3 1] [M:0]         (3 ms) -- {2^}  (0 ms)
getHardwareId:HID\VID_03F0&PID_0024&REV_0130 / Apple keyboard: 0
new keyboard: IBM keyboard      --> SEQUENCE (0)
 [1v =2 0] [M:0]         (4 ms) -- {1v}  (0 ms)
 [1^ =2 1] [M:0]         (3 ms) -- {1^}  (0 ms)
 [2v =3 0] [M:0]         (6 ms) -- {2v}  (1 ms)
 [2^ =3 1] [M:0]         (6 ms) -- {2^}  (2 ms)
getHardwareId:HID\VID_05AC&PID_0250&REV_0074&MI_00 / Apple keyboard: 1
new keyboard: Apple keyboard    --> SEQUENCE (0)
 [1v =2 0] [M:0]         (5 ms) -- {1v}  (0 ms)
 [1^ =2 1] [M:0]         (3 ms) -- {1^}  (0 ms)
 [2v =3 0] [M:0]         (3 ms) -- {2v}  (0 ms)
 [2^ =3 1] [M:0]         (3 ms) -- {2^}  (0 ms)](url)

I also tried

REWIRE A B
REWIRE B A

As well as

REWIRE a b
REWIRE b a

With the same result.

What can I do else to debug this further?
I do not presume that the version of windows can affect anything, but winver reports Version 2004 Build 19041.329

@cajhin
Copy link
Owner

cajhin commented Jul 30, 2020

What capsicain version do you use?
[ESC]+[S] shows the status

I've used this on various Win10 versions from 2017 to the latest 2004

@cajhin
Copy link
Owner

cajhin commented Jul 30, 2020

Ok, solved. You use the latest "release package". Should have updated that one day...
This release is v46 from Jan-2019. Back then you could only REWIRE modifier keys.
Look at the code base, there's a top directory "x64/release". In there is the latest v54 exe.

Update:
there is now a version v55; this includes labels for F16-F19 (ask and ye shall receive...)

@tveyben
Copy link
Author

tveyben commented Jul 31, 2020

v55 = NICE!!!!

Me using v46 in stead of v55 surely explains a lot!

Now the real test starts:
Am I able to ignore the visual input of typing on the Apple Keyboard and type "Windows" commands (aka not CMD+C / CMD+V, but CTRL+C / CTRL+V).

Thanx for all your feedback and support, it's highly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants