MOD - use a MX-Lock as Caps lock switch.

Aleksander

03 Dec 2012, 01:40

Hi, just finished modding my Pure to use a MX Lock on the Caps lock switch.
I can make a HOW-TO if somebody is interested :)
I removed the Caps lock LED in the process, as I felt is is unnecessary, but it is possible to keep that.

pictures:
Image
View of the Attiny85, two resistors and a transistor, and some messy wires :)
also note that I replaced the mini USB connector with a Micro USB connector, always interesting to get fine pitched SMD-parts to mate up with Through hole stuff.

Image
Sweeet switch in place :)

User avatar
HzFaq

03 Dec 2012, 10:38

Nice mod, would love to see a how to.

User avatar
dirge

03 Dec 2012, 11:00

Yeah please put the time into a wiki article, looks great. :)

User avatar
damorgue

03 Dec 2012, 12:45

Did you use the LED as a feedback to sense when Caps Lock is activated?
That sounds awesome, I believe the firmware I am using for my Phantom has the problem that if you activate Caps Lock without depressing the key so that it locks, then the keyboard and the OS becomes out of sync. Meaning, it will be deactivated when depressed, and activated when released back up. Your way solves that if my theory is correct. Awesome.

Aleksander

03 Dec 2012, 15:32

I will make a wiki entry later.
Will of course include the code I wrote for the attiny.

Damorgue:
Your theory is correct, so If you have another keyboard connected or use a on-screen keyboard the caps lock on that will be useless, as the chip I installed senses that the led is lit (or just the signal if you remove the led) and it will disable or enable (depending on the position of the MX-lock) the caps lock within 60 milliseconds.

JBert

03 Dec 2012, 16:33

Actually, mod how-tos belong in this forum: they are rarely updated or contributed on, and the time-based sorting of the posts in the thread allow us to see the progress of the mod.

The only problem might be layout or quick links if you want to make a very long explanation. If it is a long article, you could create a "User page" and document it there.

Aleksander

03 Dec 2012, 16:45

Ok, I will just add it in this thread later tonight, when I get home from work :)

Aleksander

03 Dec 2012, 22:44

Here is a quick guide:
Please ask me if you have any questions or if anything is unclear.

I use a transistor to simulate the momentary key-presses that the keyboard controller expects, the base input is connected via a 15K resistor to isolate the signal enough to not mess up the way the keyboard controller scans the switch matrix.

The transistor does not need to be the F422 that I have used, pretty much any NPN transistor is usable as long as you have space for it.
As we all know, most keyboards feature a diode to ensure some kind of support for multiple simultaneous key-presses, this diode is replaced by the transistor, a controllable diode, and the old switch is in effect just shorted.

Next you need to find 5v, gnd and caps lock signal, some keyboards controls the anode of the caps lock LED, some control the cathode, therefore you can measure the two connections on the LED and one of them should be connected to either +5V OR gnd, so here you can connect the appropriate 5V or gnd wire, and the other pin on the LED has the Caps Lock signal that we also need. (see notes regarding the "==" and "!=" in the code, as this changes with the whole anode/cathode-thing)

There is also a 4,7K resistor so that the signal from the switch does not float when the caps lock switch is off.

Electrical drawings:
Image

I planned on using a Attiny85 because I had some lying around, and they are tiny, as the name implies...
Unfortunately I did not have a programmer, but I was lucky to find the following guides for using an arduino as a programmer;
http://hlt.media.mit.edu/?p=1695
http://hlt.media.mit.edu/?p=1706

A added benefit of this was that I could use the simple Arduino code language to program it :D
and after some simple prototyping using a Arduino Nano, I changed some pin numbers in the program and programmed a attiny with the following code:

Code: Select all

int Lock = 0; // Input pin connected to MX Lock switch
int Capsled = 1; // Input pin connected to Caps Lock LED signal
int SwOut = 2; // Output pin connected to transistor acting as momentary caps lock switch

void setup() {
  pinMode(Lock, INPUT);
  pinMode(Capsled, INPUT);
  pinMode(SwOut, OUTPUT);
}

void loop() {
  int LockState = digitalRead(Lock);
  int CapsState = digitalRead(Capsled);
  
  if (CapsState == LockState){     // Compares the state of the switch and state of caps lock LED, change the "==" to "!=" if function is reversed
      digitalWrite(SwOut, HIGH);
      delay(10);  // time in milliseconds the simulated caps lock switch is "pressed" increase if key changes are not registered
      digitalWrite(SwOut, LOW);
   }
   delay(50);  // delay to increase stability
 }

User avatar
damorgue

04 Dec 2012, 01:46

Excellent. I am going to add this to all my keyboards. I have MX Lock on some but have always hated that they can get out of sync.

The only thing that bothers me is that if I have two keyboards connected, and both have this feature, then they will fight based on their polling and both will try to set the Caps Lock state to their respective states :P

Aleksander

04 Dec 2012, 07:06

It is possible to fix this with a small change in the code, if it is a big problem :p
But then you will have to turn the caps lock off/on or on/off to get the keyboard you want to use in sync with the computer.

on another note: I have to order some more MX locks soon, only have one or two left, and need plenty for my next project :P

bpiphany

04 Dec 2012, 09:30

It's always fun to see mods like this =) But I can't help feeling that this should be possible to do without a micro controller... I don't know how to do it myself, so all respect to Aleksander so far, but more respect to the one who gives us the ultra simple reverse-latch-whatever-send-a-signal-on-each-state-change solution =D

Aleksander

04 Dec 2012, 09:31

Yes, there is definately a way to do it but it will need several components, and what is wrong with a single, simple and cheap microcontroller? :p

Also keep in mind that this does not simply just send a pulse on state change, but when the state of the switch does not compare to the state of the caps locks state, so this will never go out of sync

User avatar
uberben

04 Dec 2012, 16:12

damorgue wrote:The only thing that bothers me is that if I have two keyboards connected, and both have this feature, then they will fight based on their polling and both will try to set the Caps Lock state to their respective states :P
The "simple" solution there is to make your own custom MX locks with solenoids or something in them so that your secondary keyboard can be locked/unlocked when your primary gets pressed :P

User avatar
uberben

04 Dec 2012, 16:14

Edit: Woops, double post
Last edited by uberben on 04 Dec 2012, 16:55, edited 1 time in total.

User avatar
damorgue

04 Dec 2012, 16:48

uberben wrote:
damorgue wrote:The only thing that bothers me is that if I have two keyboards connected, and both have this feature, then they will fight based on their polling and both will try to set the Caps Lock state to their respective states :P
The "simple" solution there is to make your own custom MX locks with solenoids or something in them so that your secondary keyboard can be locked/unlocked when your primary gets pressed :P
Then make an entire keyboard out of that switch and be able to make a self typing keyboard, which depresses its own keys just to freak out my friends. :P

Nah, not really an issue anyways. I may ask you for further details later.

Aleksander

04 Dec 2012, 16:55

uberben wrote:...make your own custom MX locks with solenoids in them...
Challenge accepted!

fart_toast

01 Dec 2013, 22:34

Why do you have to go through all this effort with resistors and transistors?

I have a Ducky Shine 2...can I not just unsolder the switch which is there and put an MX LOCK there?

User avatar
Daniel Beardsmore

01 Dec 2013, 23:55

Why, does the Ducky Shine 2 have support for an alternate action caps lock switch as well as a momentary caps lock switch?

MX Lock is a latching or alternate action switch: when you press it, it stays down, during which time it registers continually as closed. Press it again, and it reverts to open. Normally, caps lock is a momentary switch, i.e. it on registers while you're holding it down with your finger. Each press and release tells the OS to toggle caps lock state.

Try this exercise:

Press caps lock once: the caps lock LED comes on
Now press and hold caps lock down: the caps lock light goes off, yet you're holding the key down!

Caps lock on a normal PC bears no relation to whether the key is pressed. Caps lock state changes every time the key is pressed, not when it's released. Were you to solder in an MX Lock switch, when you press MX Lock down, caps lock instantly engages, without waiting for release. When you press MX Lock again to release it, nothing will happen, as caps lock state changes on press, not release. When you press and lock MX Lock again, caps lock disengages, leaving the switch and the OS in disagreement.

That's also why he's reading the LED state: the OS is free to change caps lock at will, and then the OS and the switch will disagree with each other. His circuit simulates caps lock being pressed again, to force the OS to agree with the switch, since MX Lock visibly displays state by not rising fully when you release the key after it latches.

MX Lock needs to be read differently from a momentary switch, i.e. caps lock is no longer a toggle in RAM, but a toggle in hardware.

User avatar
Nuum

02 Dec 2013, 01:06

It would be easier to totally cut the lines to the Caps Lock switch and connect the MX Lock Switch to the Shift switch with some short wires. This way the normal Shift key stays pressed, if you lock the caps lock.
Unfortunately you don't get an LED signal, then. And you can't temporarily unlock caps lock by pressing shift.
It's just easier to do, but your solution seems better.

Edit: Or maybe you could do it with AutoHotKey, e.g. toggle Capslock on key press and untoggle on key release.

Aleksander

02 Dec 2013, 08:59

Daniel pretty much explained the whole thing :)

you COULD use it as a shiftlock, and a shiftlock comes in handy some times, but there is the problem with all the other stuff that rests on the shift-layer... Typing numbers, ".", "-" etc. would require you to disable the shiftlock.

Also spamming the computer with either shift or capslock commands is not good practice, and if you have a keyboard with a low key roll-off, that also spoils the fun. :P

fart_toast

02 Dec 2013, 15:53

Ah sorry, I didn't realise that it constantly registered once depressed. I thought it may have returned upwards somewhat to disengage at the contacts. Good job I didn't go about putting one on my board ill-informed!

Thanks for the great explanation

That shift key method sounds like a good bet!

User avatar
damorgue

02 Dec 2013, 21:22

For the record, hasu added support for MX Locks to his TMK firmware and it can sync with the OS. Since the OS sends data about the state of the Caps Lock LED, the keyboard knows the state of the OS and can sync them up.

User avatar
Muirium
µ

02 Dec 2013, 21:33

Indeed. The controller is the ideal place for logic like this. Fine for a custom, but when modding… needs must.

User avatar
Daniel Beardsmore

02 Dec 2013, 21:54

What you need is a solenoid-drive switch so that when you're swapping between remote sessions, the switch can engage and disengage by itself … Also, MS Word has a feature that can disengage caps lock when it believes that it's enabled by mistake, and it would be funny for that feature to be accompanied by a corresponding click as the caps lock key pops back up.

Aleksander

03 Dec 2013, 17:32

I actually did this to a Poker today, this time it looks a bit cleaner :)
Image

Post Reply

Return to “Workshop”