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

Macros send random characters #4801

Closed
luandy64 opened this issue Jan 8, 2019 · 8 comments
Closed

Macros send random characters #4801

luandy64 opened this issue Jan 8, 2019 · 8 comments

Comments

@luandy64
Copy link

luandy64 commented Jan 8, 2019

I'd like someone to replicate my issue and prove my solution works. Then we can change the docs accordingly.

Problem:

Following the docs to define a macro, I write the following code:

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    switch (keycode) {
        case MY_MACRO:
            if (record->event.pressed){
                SEND_STRING("Hello World");
            }
        break;
    }
    return true;
}

When I go to use MY_MACRO, I get "Hello World" and some other character at the end (Multiple tests have given me multiple things, like a + or : or |).

Solution:

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    switch (keycode) {
        case MY_MACRO:
            if (record->event.pressed){
                SEND_STRING("Hello World");
            }
        return false;
        break;
    }
    return true;
}

Now the macro works as intended.

I question whether we need both the return false; and the break. I didn't look into and I am not confident in my C skills to make a confident statement about this. But I have return false; break; in my keymap right now and it's working.

@vomindoraan
Copy link
Contributor

vomindoraan commented Jan 8, 2019

Could you link to where exactly in the docs you found this?

The return false; is indeed required. The break; isn't as the return statement already serves to break the switch.

@luandy64
Copy link
Author

luandy64 commented Jan 9, 2019

Here's the link

@vomindoraan
Copy link
Contributor

While the tutorial is technically correct and return false isn't required since the macro keycode is >= SAFE_RANGE, it'd still be nice to have it there. In your case, how did you define the MY_MACRO keycode?

@luandy64
Copy link
Author

luandy64 commented Jan 9, 2019

Just in an enum with a bunch of other things.

enum custom_keycodes {
    QWERTY = SAFE_RANGE,
    ...
    MY_MACRO
};

Is this the proper way of doing it?

@vomindoraan
Copy link
Contributor

It is, but then it shouldn't have caused any issues. Could you share the whole enum?

@luandy64
Copy link
Author

enum preonic_keycodes {
  QWERTY = SAFE_RANGE,
  LOWER,
  RAISE,
  TMUX_LD = LCTL(KC_RBRC),
  TMUX_SC, // TMUX Scroll
  TMUX_LO, // TMUX LogOut
};

where MY_MACRO is TMUX_LO

@vomindoraan
Copy link
Contributor

vomindoraan commented Jan 10, 2019

As I suspected, the problem is that you're explicitly assigning a value to one of the enum members that come after SAFE_RANGE. This is not allowed. Replace TMUX_LD = LCTL(KC_RBRC), with just TMUX_LD, and it should work.

If you want TMUX_LD to be a simple alias for LCTL(KC_RBRC), move it out of the enum and use #define TMUX_LD LCTL(KC_RBRC) instead.

@luandy64
Copy link
Author

Thanks for all of your help @vomindoraan!

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