cajhin / capsicain

Powerful low-level keyboard remapping tool for Windows
349 stars 18 forks source link

Help Replacing Simple AHK Script with Capsicain Script #12

Closed DGCupit closed 3 years ago

DGCupit commented 3 years ago

Any thoughts of making an AHK script to Capsicain converter?

Also, is there a list of Keys, like on the AHK site? Or are all the keynamings the same?

I'm not trying to do anything fancy at all - I just want to remap common WASD FPS shooter key layout to a right-side keyboard layout. I normally use AHK for this, but it seems that some games just completely ignore AHK - Like the new Cyberpunk 2077. AHK does nothing in this game.

Here's my AHK script. It's really, really simple - ScrollLock is my toggle to activate / deactivate mappings:

ScrollLock::Suspend
Up::w
Down::s
Left::a
Right::d
Enter::r
Home::i
End::e
\::LShift
RShift::c
RCtrl::Space
PgUp::TAB
PgDn::t
Ins::f
Del::LAlt
BackSpace::Esc
Numpad0::v
Numpad1::q
Numpad3::b
Numpad4::LCtrl
Numpad5::m
Numpad7::g
Numpad8::x
Numpad9::z
NumpadDot::j
NumpadEnter::Enter
w::Up
s::Down
a::Left
d::Right
cajhin commented 3 years ago

ya one a those corpo slimebags? Hope not, hombre, so here's the tutorial mission for hacking (keyboards)...

Put this in your .ini

[LAYER_1]
REWIRE Up W
REWIRE Down S
REWIRE Left A
REWIRE Right D
REWIRE Ret R
REWIRE Home I
REWIRE End e
REWIRE L\   #this is the backslash next to left shift, only on Euro/ISO boards
REWIRE RShf c
REWIRE RCtrl Space

#do the rest of the mappings here

[LAYER_2]
# does nothing. Usually you use ESC+0 = layer_0 to disable capsicain, but ESC+2 is easier to press without taking your hand off the mouse

Two ways to look up the capsicain key labels:

  1. press ESC+C in capsicain to see the full list
  2. press ESC+D for debug mode. Press the key you're looking for, label is on the left (e.g. 'NP1' for 'Numpad 1 key') Note that some laptops send an second funny key for the number block, which you can ignore.

You can't "toggle" capsicain on and off, you can only change layers from "my customized layer 1" to "my standard layer 2", or "do nothing layer 0". Right now changing layers is hardcoded to ESC+(number). I could make it configurable if there's a benefit.

Making a converter... feel free to make one, for the simple key mappings it's probably easy :)

DGCupit commented 3 years ago

Thanks very much for the reply! No, I'm just a simple gamer trying to work around the ahole devs who decide they will lock or limit keyboard remapping of key controls in PC game releases.

Hmm. For whatever reason, when the app opens, ESC-C and ESC-D do not do anything. The window shows no status changes. It just remains as seen here:

http://picturethisquote.com/Misc/Untitled.png

ESC-X does close the app, but ESC-H does nothing, too.

DGCupit commented 3 years ago

Okay, I found that if I go back to the default INI, then those keys do work.

DGCupit commented 3 years ago

I know you're obviously very familiar with your app, so can you tell me what lines to add to my script to make the ESC 1 toggle the remapping on and off? I've looked at your default ini, but I can't find it.

I saw your comment, but I don't understand how to implement it:

[LAYER_2]
# does nothing. Usually you use ESC+0 = layer_0 to disable capsicain, but ESC+2 is easier to press without taking your hand off the mouse

Also, since I'm remapping (swapping) ESC and BACKSPACE, wouldn't that also affect the ESC command for exiting, suspending, etc?

BTW, here's my script.

[LAYER_1]
REWIRE UP W
REWIRE DOWN S
REWIRE LEFT A
REWIRE RIGHT D
REWIRE RET R
REWIRE HOME I
REWIRE END E
REWIRE \ LSHF
REWIRE RSHF C
REWIRE RCTRL SPACE
REWIRE T PGDOWN
REWIRE F INS
REWIRE LALT DEL
REWIRE ESC BSP
REWIRE V NP0
REWIRE Q NP1
REWIRE B NP3
REWIRE LCTRL NP4
REWIRE M NP5
REWIRE G NP7
REWIRE X NP8
REWIRE Z NP9
REWIRE J NP.
REWIRE ENTER NPRET
REWIRE UP W
REWIRE DOWN S
REWIRE LEFT A
REWIRE RIGHT D
REWIRE BSP ESC
#do the rest of the mappings here

[LAYER_2]
# does nothing. Usually you use ESC+0 = layer_0 to disable capsicain, but ESC+2 is easier to press without taking your hand off the mouse
DGCupit commented 3 years ago

I guess I really don't know what I'm doing. Although I have my script named capsicain.ini, when I start the .exe, none of the mappings seem to be working. But if I return your .ini then those mappings seem to work. Obviously my ini is missing something important.

cajhin commented 3 years ago

I can recreate your problem. Thanks for the info. Sorry, you ran into a bug or three. I'll look into this.

  1. Rewiring the Escape key goes haywire, I never tried that before.
  2. on layer 0 ('capsicain disabled') only the ESC+Number combos work...
  3. completely empty sections are ignored (so it switches to layer 0 instead).

Here's your cleaned up script. You can't rewire the escape key until I fix that.

GLOBAL IniVersion version2
GLOBAL ActiveLayerOnStartup 1

[LAYER_1]
OPTION layerName game_config
REWIRE UP W
REWIRE DOWN S
REWIRE LEFT A
REWIRE RIGHT D
REWIRE RET R
REWIRE HOME I
REWIRE END E
REWIRE \ LSHF
REWIRE RSHF C
REWIRE RCTRL SPACE
REWIRE T PGDOWN
REWIRE F INS
REWIRE LALT DEL
#REWIRE ESC BSP
REWIRE V NP0
REWIRE Q NP1
REWIRE B NP3
REWIRE LCTRL NP4
REWIRE M NP5
REWIRE G NP7
REWIRE X NP8
REWIRE Z NP9
REWIRE J NP.
REWIRE RET NPRET
REWIRE UP W
REWIRE DOWN S
REWIRE LEFT A
REWIRE RIGHT D
#REWIRE BSP ESC

[LAYER_2]
OPTION layerName do_nothing
# does nothing. Usually you use ESC+0 = layer_0 to disable capsicain, but ESC+2 is easier to press without taking your hand off the mouse

Note: one more thing: you cannot 'toggle' layers with a single key. You can switch to layer 1 (your config), or switch to layer 2 (do nothing)

DGCupit commented 3 years ago

Great! Thanks very much. I'll be giving this updated script a try this evening and let you know.

I don't guess the ESC remapping is a huge deal. It just seems like a lot of games have you pressing ESC to close menus and whatnot, and with my need to use the right-side of the keyboard, I suppose I'll just have to get used to reach over to tap that key as well.

Any way to send the ESC key code via another key without actually remapping the ESC key? Like add a 2nd ESC key with your software?

As for the toggle, could a combo mapping be done to send ESC-2 when a single key is pressed? Like make ScrollLock send ESC-2? Does ESC 2 only turn it off? Do you send ESC 1 to turn it on? I'm sure these questions seem stupid.

Thanks for your help!

cajhin commented 3 years ago

in Code/x64/Release you can download the latest capsicain.exe v60 Haven't used it much, I'd call it a beta.

With that version you can REWIRE from and to ESC. Just uncomment the two lines in your ini that are commented out.

Note that the physical ESC key is a bit special. You can only rewire it to plain keys. Not sure what would happen if you rewire it to a modifier (it won't work right).

About your other question, what you want is a new function in your .ini, to switch/toggle layers. Like "TAB [...] > switchToLayer (1)" That's not possible today.

What's the use case for needing to "toggle" between two layers? Can you describe a situation where this is better than having two dedicated keys for two layers? (I don't like toggles very much, you need to know where you are before you press the toggle key. ESC+1 gives you layer 1, always, unconditional).

DGCupit commented 3 years ago

For the on/off - I just got used to AutoHotKey, and its suspend function. I am in the habit of reach up, taping scrolllock, then being able to type as normal (in a chat window, etc) and then when I'm done, I just tap scrolllock again, and the remappings kick in again. Just quicker than clicking esc-1, esc-2. The ScrollLock light also works as an ON/OFF indicator, too.

I found this handy site. It puts an onscreen keyboard and highlights what keys are being pushed:

https://www.keyboardtester.com/

I noticed I had some of my rewire's backwards. AHK uses Remap=Original script entries, and your app uses Original=Remap and I had a mix accidentally. I corrected those and so I think all mappings are working now.

BTW, If I remap ESC to BSP, the onscreen keyboard shows I'm pressing ALL the command keys at once! ALT, CTRL, ESC, etc... So that doesn't work as intended. I'll leave ESC alone, I guess.

Also, I didn't see an answer to my question about the ability to make another key also be an ESC key? Is that possible?

And if anyone cares, this is the final script (no ESC remapping)

GLOBAL IniVersion version2
GLOBAL ActiveLayerOnStartup 1

[LAYER_1]
OPTION layerName game_config
#REWIRE ESC BSP
#REWIRE BSP ESC
REWIRE UP W
REWIRE DOWN S
REWIRE LEFT A
REWIRE RIGHT D
REWIRE RET R
REWIRE HOME I
REWIRE END E
REWIRE \ LSHF
REWIRE RSHF C
REWIRE RCTRL SPACE
REWIRE PGUP TAB
REWIRE PGDOWN T
REWIRE INS F
REWIRE DEL LALT
REWIRE NP0 V
REWIRE NP1 Q
REWIRE NP3 B
REWIRE NP4 LCTRL
REWIRE NP5 M
REWIRE NP7 G
REWIRE NP8 X
REWIRE NP9 Z
REWIRE NP. J
REWIRE NPRET RET
REWIRE UP W
REWIRE DOWN S
REWIRE LEFT A
REWIRE RIGHT D

[LAYER_2]
OPTION layerName do_nothing
# does nothing. Usually you use ESC+0 = layer_0 to disable capsicain, but ESC+2 is easier to press without taking your hand off the mouse
cajhin commented 3 years ago

There's a new version 62, I tested the ESC stuff and cleaned up the code. I'm somewhat confident it works correctly now.

You can rewire any key to ESC, that's now clean and simple.

You can rewire ESC to another key, but that comes with 'buts'

The hardware ESC key is a bit special since it must trigger the capsicain commands.

Having scrollLock (with LED, nice) to turn key mapping on/off sounds nice, though. I'll mark that as a possible feature.

DGCupit commented 3 years ago

Very good! I'll give things a try with the new build and try that ESC to BSP remapping.

cajhin commented 3 years ago

done. You can now define

GLOBAL capsicainOnOffKey ScrLock

To turn capsicain ON/OFF with the ScrLock key. And the LED indicates the state...

DGCupit commented 3 years ago

Hey, very cool! I appreciate you adding this feature!

cajhin commented 3 years ago

Let me know if anything isn't 100% In don't have a ScrollLock key on my usual keyboards, and I never turn capsicain off myself. I tested it, but not for a long time.