geekhack

geekhack Community => Keyboards => Topic started by: zer09 on Sat, 18 November 2017, 21:12:52

Title: QMK how to get the pressed key?
Post by: zer09 on Sat, 18 November 2017, 21:12:52
Hello good day,

I just want know if there is way to get the pressed row and column position?

Thanks.
Title: Re: QMK how to get the pressed key?
Post by: zer09 on Sat, 18 November 2017, 23:28:45
I got the columns and rows using this.
Code: [Select]
  for (uint8_t c = 0; c < MATRIX_COLS; c++) {
    for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
      if (matrix_is_on(r, c)) {
        row_pressed = r;
        col_pressed = c;
        xprintf("r1:%d c1:%d \n", r, c);
        break;
      }
    }
  }

It give me the right result, but I don't know if it is the right way to this.
May be there is already a function to this, I don't want to reinvent the wheel.
Title: Re: QMK how to get the pressed key?
Post by: ErgoMacros on Sun, 19 November 2017, 01:49:20
I don't know much, but in case it matters this will only find and report 1 key that's down.
I suppose that's OK if you're just typing one key at a time to map out a board.
Title: Re: QMK how to get the pressed key?
Post by: zer09 on Sun, 19 November 2017, 02:54:09
Probably. I tried activating two keys, and the debug print show that it alternates between the two keys.

But I can't tell what will be the final result, I am still testing it on the breadboard.
Title: Re: QMK how to get the pressed key?
Post by: zer09 on Sun, 19 November 2017, 20:24:33
Got better solution here: https://www.reddit.com/r/olkb/comments/7dxr2i/the_pressed_key_in_the_matrix/ (https://www.reddit.com/r/olkb/comments/7dxr2i/the_pressed_key_in_the_matrix/)