Mapping International Characters

The host os guessing hasn’t worked for me either, tbh…Looking at FingerprintUSBHost, it seems like we could do a lot to try to improve it, as it is very simple right now – as the comments there say, it is mainly a proof-of-concept by Jesse.

I don’t know much about how that might work, but I will give it a go at some point in the near future.

2 Likes

So with the real danger that I am exposing, that I have still not understood anything about shifting …

I hard coded the OS to Mac OS and set the keyboard to unicode.
So now I can map æøå to the fn layer. Yay!

Now I am trying to extend the macro to handle that if shift was pressed, it should send another unicode instead. But it doesn’t work. With shift the small letters are sent anyway.

Here is my macro:

static void unicode(uint32_t codepoint, uint8_t keyState) {
  if (!keyToggledOn(keyState)) {
    return;
  }
  Unicode.type(codepoint);
}

const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  bool shifted = kaleidoscope::hid::isModifierKeyActive(Key_LeftShift)
              || kaleidoscope::hid::isModifierKeyActive(Key_RightShift);

  switch (macroIndex) {
    case L_AE:
      unicode(shifted ? 0x00c6 : 0x00e6, keyState);
      break;
    case L_OE:
      unicode(shifted ? 0x00d8 : 0x00f8, keyState);
      break;
    case L_AA:
      unicode(shifted ? 0x00c5 : 0x00e5, keyState);
      break;
  }
  return MACRO_NONE;
}

The bool shifted was lifted from @james.nvc bitbucket link at the start of this thread. So I was hoping it might just work.

Can any of you see what might go wrong with this code.

Ha, so I wrote that code before I had a keyboard to test on, and now that I do I also see that it doesn’t work. I will try to figure out what’s going wrong & report back.

1 Like

Thanks. I have never done any arduino before. I am mostly a java guy and I get stumped pretty fast in this environment :blush:

I am in the same boat, tbh :stuck_out_tongue: Just trying to read the source enough to figure things out…

Do you think this thread holds an answer?

Hrm, I’m not sure. Reading the source seems to indicate that the isModifierKeyPressed is ultimately checking the keyReport that Jesse talks about in that thread…my thought is maybe we’re checking this in the wrong place? I looked at the source for ShapeShifter, which checks if the shift keys are held in the same way that we’re trying here, but it does the check in the loop and refers to it later…I will give that a try.

(There’s also a wasModifierKeyPressed, but I don’t think that’s what we want either)

I wonder if it would be possible to map fn + shift to a new layer?

I think that would be straightforward enough to do by putting a ShiftToLayer(whatever) on the shift key in the fn layer.

I’m realizing that, for Linux at least, the situation for this may be complicated by the fact that entering Unicode characters entails faking holding down a shift key, which may be breaking this? I feel like it should work on macOS at least thought. I am a little confused.

1 Like

The reason why checking in the report does not work is that we clear the report each cycle, and fill it again. If your shift is later on the matrix than the unicode symbols, when we process the symbols, shift won’t be re-added yet. This is why ShapeShifter checks it in the loop hook too.

This is something we need to address one way or the other, because checking modifier state is going to be a very common thing.

1 Like

One way or another, I will make this happen, but I won’t bet on it being pretty or easy to duplicate. And I won’t be able to do much until I have hardware, which will be January for me.

Why does the report get cleared every cycle? It’s really odd to have a function named isModifierPressed() that sometimes tells you the key isn’t pressed when it actually is.

The report gets cleared so we can avoid having to do manual bookeeping, which can very, very easily lead to a whole lot of bugs. And yes, it is odd to have it named like that, and it is something I want to fix. It’s not a trivial task (and switching to manual bookeeping is not an option, not in my book).

Also very interested (on behalf of Kaleidoscope-MacrosOnTheFly) in these kinds of press/release issues

Perhaps it could build the new report without clearing the old one first, and replace the old report by overwriting a pointer in a single step? Or is that what the was*Pressed() functions have access to? (Forgive me; I don’t have time to search the code to figure that out myself right now.)

It is.

(The main use case for the isModifierPressed code right now, is a workaround for a chromeos bug. When called late enough in the flow, it is accurate and useful. I’d argue that the failures folks are seeing with it are due to me not documenting its intended use and what behaviour you should expect from it)

1 Like

As luck will have it, I just sent in a PR to improve that error message. Jesse wanted it to read slightly differently; I should clean that up and send it back in…

2 Likes

So … any suggestions on how to get so send one unicode when I press fn and another when I press shift + fn?

I tried adding a layer when shift is held in the fn layer, but that doesn’t work for me either …

Can you try if the commented out isModifierActive stuff works, if you change it to wasModifierActive? You can then change the case statements to also have an if (shifted) { /* send uppercase */ } else { /* send lowercase */ } body.

2 Likes

What do you get when you type Fn+shift+unicode macro when using that sketch?

1 Like

Yes! It works with that change!
Thank you very much. Now I think I have all the pieces to finalize my layout. :smiley:

3 Likes