TMK keyboard firmware collection

User avatar
sphinx
Major Bummer

18 Apr 2016, 14:08

hey there, i'm trying to get the firmware running on my custom handwired keyboard... i followed matt3o's tutorial and managed to compile and load the code on to the teensy.

using hid_listen, when i connect the keyboard to the usb i get this output:

Code: Select all

Listening:
done.
Keyboard start.
and then nothing works.

am i missing something really basic or could this be some spooky weird stuff ?

e_l_tang

28 Apr 2016, 04:50

@sphinx Does your keyboard register keystrokes?

User avatar
rddm

28 Apr 2016, 05:09

@sphinx if you want I can speak with you in Portuguese via skype, mobile, etc and tell you how to do it, but it is 4 am so lets say tomorrow.

User avatar
sphinx
Major Bummer

28 Apr 2016, 10:13

Eric-T wrote: @sphinx Does your keyboard register keystrokes?
it does now, but not with my code.. i used this tool to generate a compiled hex file and it worked: http://kb.sized.io/

at least i know the switches are soldered correctly now :P
rddm wrote: @sphinx if you want I can speak with you in Portuguese via skype, mobile, etc and tell you how to do it, but it is 4 am so lets say tomorrow.
thanks! right now I don't have much time to work on it, probably will pick it up again by the end of the month..

User avatar
Cortes

19 May 2016, 14:12

How I can do that by pressing a key, type "hello"?

User avatar
hasu

19 May 2016, 19:09

Cortes wrote: How I can do that by pressing a key, type "hello"?
You can use macro. The document is always sparse and not updated you will have to read code or look into other's keymap files.
https://github.com/tmk/tmk_keyboard/blo ... cro-action

User avatar
vvp

19 May 2016, 21:41

Can one record a macro on the fly like on Kinesis Advange?
Or remap a key on the fly?

User avatar
matt3o
-[°_°]-

20 May 2016, 09:14

hasu wrote:
Cortes wrote: How I can do that by pressing a key, type "hello"?
You can use macro. The document is always sparse and not updated you will have to read code or look into other's keymap files.
https://github.com/tmk/tmk_keyboard/blo ... cro-action
this must be the silliest question, but how do you assign the macro to a key? you just use "HELLO" in the key matrix?

Also what is the "record->event.pressed"? is TRUE when any event on the key is performed (press/release/type)?

User avatar
flabbergast

20 May 2016, 11:36

Macros are done via FN, so you assign FN8 in that example.

The parameter in the ACTION_MACRO is just a number, but using labels is helpful.

In the definition - this gets called both when FN8 is pressed (then record->event.pressed is true) and then FN8 is released (then it's false).

The definitions of the relevant structures: keyrecord_t, keyevent_t.

User avatar
matt3o
-[°_°]-

20 May 2016, 11:49

you know I'm dumb, flabbergast.

Code: Select all

            return (record->event.pressed ?
                    MACRO( D(LALT), D(TAB), END ) :
                    MACRO( U(TAB), END ));
are you saying that this code executes both an ALT+TAB and a TAB whenever you press and release the function key?

User avatar
scottc

20 May 2016, 13:08

Without much context, I can try to help. That's a C ternary statement: it's a small conditional. It could also be written as if-else:

Code: Select all

if (record->event_pressed) {
  a = foo;
} else {
  a = bar;
}
return a;
I was a bit lazy with the code example here because I'm typing this on my phone!

It looks like it presses LALT and TAB down when the key is pressed, and otherwise (= key released) it releases TAB (but not LALT?).

User avatar
flabbergast

20 May 2016, 13:24

Need to also interpret the 'D(..)' and 'U(..)'. Forget where the docs are; but from memory 'D' is for 'down', 'U' is for 'up', 'T' is for 'tap' (='down'+pause+'up').

So that macro does 'press down alt+tab' (and keep pressed) when FN8 is pressed down, and 'release the tab' when FN8 is released {not sure about alt, maybe it gets cleared automatically?}.

If you want just to write 'HELLO' you can use 'T'. I forget what the 'I' means, and I think 'W' is 'wait' - but not sure about that. Need to dig out the docs, I've seen it somewhere...

EDIT: didn't find the docs, but it's a bit documented in the sources.

User avatar
matt3o
-[°_°]-

20 May 2016, 13:46

okay I know what a ternary statement is, it's the macro that still looks a bit strange to me.

I would have expected to see at least U(LALT) in the release phase, but possibly that is not needed?

User avatar
hasu

21 May 2016, 00:09

My ALT_TAB macro uses 'dirty trick' to meet my specific need. It is confusing for example code.
Modifier keys pressed in macro are cleared automatically when switching layers in current implementation at least, the trick depends thoroughly on this. This trick may not work in future.

Yes, you basically need U(ALT) in release macro.

User avatar
flabbergast

21 May 2016, 00:35

Ah! Sorry - I didn't mean to publicise this much, it is just that this was the only macro actually used in your keymap :)

User avatar
hasu

04 Jun 2016, 17:45


User avatar
Hypersphere

12 Jun 2016, 16:23

I just wanted to add my thanks to hasu for his inspired dedication and hard work on the hardware and software that provides excellent complementarity to Soarer's converter. This inventiveness makes it possible to breathe new life into vintage keyboards and to remap new and old keyboards to your heart's content.

Initially, I was somewhat daunted by the code, but now that hasu has created online configurators for generating hex files, I found it very easy to program an Alps64 board and hasu's miraculous USB to USB converter.

As a preliminary test of the USB-USB converter, I programmed it to a HHKB-like layout, using R_Ctrl as Fn. I plugged in a KBP V60MTS-C and then a CM QFS TKL, and each keyboard responded with my HHKB layout. Magic!

I did notice one thing that didn't work as expected. I had programmed the key to the left of the "1" key as "Esc" in the default layer and as "Backtick/Tilde" in the Fn layer. This worked on the CM QFS TKL but not on the V60. Everything else worked flawlessly on both keyboards.

I frequently rotate keyboards, and I would also like to travel with the hasu USB-USB converter so that I will have my HHKB layout available on other computers. However, I am concerned about the mechanical stability of the converter. Does anyone have ideas about strengthening the converter to help ensure that the connectors do not detach from the PCB? I am considering making an enclosure for the converter that could include internal strain-relief cables leading to panel-mount connectors; there would also be a window for viewing the LED and a small opening for access to the bootloader button. Maybe this is being overly cautious, but the USB-USB converter is certainly worth protecting!

User avatar
Mr.Bean

23 Jun 2016, 23:21

I'm having this strange problem with my new layout. There is a quite noticeable delay when I hit space which is bind to

Code: Select all

[0]  =  ACTION_LAYER_TAP_KEY(1, KC_SPC)
I'm using hasu's custom controller for HHKB. Any ideas? Here is my full layout

Code: Select all

/*
 * HHKB Layout
 */
#include "keymap_common.h"


#ifdef KEYMAP_SECTION_ENABLE
const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
#else
const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
#endif

    [0] = \
	KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSLS,GRV,   \
		   TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSPC,       \
		   LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,ENT,             \
		   LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT, MPLY,           \
				LALT,LGUI,          FN0,                RGUI,RALT),

    [1] = \
	KEYMAP(ESC, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, INS, DEL,   \
	CAPS, WH_U, MS_U, WH_D, TRNS, MSTP, TRNS, TRNS, PSCR, SLCK, PAUS, MPRV, MNXT, BSPC, \
	LCTL, MS_L, MS_D, MS_R, BTN2, BTN3, LEFT, DOWN, UP, RIGHT, TRNS, TRNS, ENT, \
		   LSFT,VOLD,VOLU,MUTE,FN1,FN2,HOME,PGDN, PGUP, END, TRNS, RSFT, TRNS, \
				LALT,LGUI,          TRNS,               RGUI,RALT),
};

enum macro_id {
    M1,
    M2,
};
/*
 * Fn action definition
 */
#ifdef KEYMAP_SECTION_ENABLE
const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = {
#else
const uint16_t fn_actions[] PROGMEM = {
#endif
	[0]  =  ACTION_LAYER_TAP_KEY(1, KC_SPC),
    [1]  =  ACTION_MACRO(M1),                 // F1  = =>
    [2]  =  ACTION_MACRO(M2),                 // F2  = ->
};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
    switch (id) {
        case M1:
            return (record->event.pressed ?
                    MACRO( T(EQL), D(LSHIFT), T(DOT), END ) :
                    MACRO_NONE );
        case M2:
            return (record->event.pressed ?
                    MACRO( T(MINS), D(LSHIFT), T(DOT), END ) :
                    MACRO_NONE );
    }
    return MACRO_NONE;
}
And here is Makefile

Code: Select all

#----------------------------------------------------------------------------

# Target file name (without extension).
TARGET = hhkb_lufa

# Directory common source filess exist
TMK_DIR = ../../tmk_core

# Directory keyboard dependent files exist
TARGET_DIR = .


# List C source files here. (C dependencies are automatically generated.)
SRC +=	keymap_common.c \
	matrix.c \
	led.c

CONFIG_H = config.h


# MCU name
# PJRC Teensy++ 2.0
#MCU = at90usb1286
# TMK Alt Controller or PJRC Teensy 2.0
MCU = atmega32u4


F_CPU = 16000000


#
# LUFA specific
#
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8


F_USB = $(F_CPU)

# Interrupt driven control endpoint task
#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT


# Boot Section Size in *bytes*
#   Teensy halfKay   512
#   Teensy++ halfKay 1024
#   Atmel DFU loader 4096	(TMK Alt Controller)
#   LUFA bootloader  4096
#   USBaspLoader     2048
OPT_DEFS += -DBOOTLOADER_SIZE=4096


# Build Options
#   comment out to disable the options.
#
# BOOTMAGIC_ENABLE = yes		# Virtual DIP switch configuration
# MOUSEKEY_ENABLE = yes		# Mouse keys
EXTRAKEY_ENABLE = yes		# Audio control and System control
# CONSOLE_ENABLE = yes		# Console for debug
# COMMAND_ENABLE = yes    	# Commands for debug and configuration
NKRO_ENABLE = yes		# USB Nkey Rollover
#KEYMAP_SECTION_ENABLE = yes	# fixed address keymap for keymap editor
#HHKB_JP = yes			# HHKB JP support

#OPT_DEFS += -DNO_ACTION_TAPPING
#OPT_DEFS += -DNO_ACTION_LAYER
#OPT_DEFS += -DNO_ACTION_MACRO


#
# Keymap file
#
ifdef KEYMAP
    SRC := keymap_$(KEYMAP).c $(SRC)
else
    ifdef HHKB_JP
    	SRC := keymap_jp.c $(SRC)
    else
    	SRC := keymap_hhkb.c $(SRC)
    endif
endif


ifneq (, $(or $(findstring keymap_jp.c, $(SRC)), $(findstring yes, $(HHKB_JP))))
    OPT_DEFS += -DHHKB_JP
endif


# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TMK_DIR)

include $(TMK_DIR)/protocol/lufa.mk
include $(TMK_DIR)/common.mk
include $(TMK_DIR)/rules.mk

debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
debug-on: all

debug-off: EXTRAFLAGS += -DNO_DEBUG -DNO_PRINT
debug-off: OPT_DEFS := $(filter-out -DCONSOLE_ENABLE,$(OPT_DEFS))
debug-off: all

User avatar
hasu

24 Jun 2016, 05:10

That delay is inevitable for dual role key(TAP_KEY), give up it if you cannot stand the delay.
You can tune length of the delay somewhat with TAPPING_TERM.
https://github.com/tmk/tmk_keyboard/blo ... #4-tapping

User avatar
Mr.Bean

25 Jun 2016, 15:29

Thanks, i guess i have to adapt.

Salt

25 Jun 2016, 19:56

Hi I posted a thread on Geekhack but it doesn't seem to get any response so I guess I will try here aswell. I have built my own handwired keyboard using matt30s informative guides at deskthority. Unfortunately I've hit a small bump and I am finding it very difficult to solve it so I was hoping that one of you might know what is causing the issue. The issue in hand has to do with specific keymappings not appearing on the right switch. If you look at the layout for my keyboard down below I will give you a quick example: http://imgur.com/2vm8ahY.


The rightmost column which should contain Pgup, Pgdn, home, end, arrowup, arrowdown will only respond to the pgup and arrowdown switches, the rest of the switches are non responsive. I have tried switching colums/rows on the teensy and replacing switches/diodes on the keyboard but I think it is a software problem since I discovered that most of the layout is shifted one column to the left except some keys. Home appears where Enter should be and End appears on the button left of enter etc.. Backspace is nowhere to be found.

Here is some of the code for the controller, if you need to see anything else to diagnose the problem let me know! At this point I am thinking I have a faulty controller unless there is something wrong with the code.
Keymap_common.h

Code: Select all

#define KEYMAP( \
K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F,\
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, 	   K1F,\
K20,   	  K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D,      K2F, \
K30,      K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E, K3F, \
K40,      K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B, K4C, K4D,      K4F, \
K50,      K52, K53,           K56,                     K5B, K5C, K5D, K5E, K5F  \
) { \
{KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_##K0F }, \
{KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1F}, \
{KC_##K20, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2F }, \
{KC_##K30,KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E,  KC_##K3F }, \
{KC_##K40, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47, KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4F }, \
{KC_##K50, KC_NO, KC_##K52, KC_##K53, KC_NO, KC_NO, KC_##K56, KC_NO, KC_NO, KC_NO ,KC_NO, KC_##K5B, KC_##K5C, KC_##K5D, KC_##K5E, KC_##K5F}  \
}
Matrix.c
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRD  &= ~(1<<7 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    PORTD |=  (1<<7 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    DDRC  &= ~(1<<7 | 1<<6);
    PORTC |=  (1<<7 | 1<<6);
    DDRE  &= ~(1<<6);
    PORTE |=  (1<<6);
    DDRB  &= ~(1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 |1<<2);
    PORTB |=  (1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 |1<<2);
}

static matrix_row_t read_cols(void)
{
    return (PINB&(1<<6) ? 0 : (1<<15)) |
           (PINB&(1<<5) ? 0 : (1<<14)) |
           (PINB&(1<<4) ? 0 : (1<<13)) |
           (PIND&(1<<7) ? 0 : (1<<12)) |
           (PIND&(1<<4) ? 0 : (1<<11)) |
           (PIND&(1<<5) ? 0 : (1<<10)) |
           (PINC&(1<<6) ? 0 : (1<<9))  |
           (PIND&(1<<3) ? 0 : (1<<8))  |
 	   (PIND&(1<<2) ? 0 : (1<<7))  |
           (PIND&(1<<1) ? 0 : (1<<6))  |
           (PIND&(1<<0) ? 0 : (1<<5))  |
           (PINB&(1<<7) ? 0 : (1<<4))  |
	   (PINB&(1<<3) ? 0 : (1<<3))  |
	   (PINB&(1<<2) ? 0 : (1<<2))  |
	   (PINC&(1<<7) ? 0 : (1<<1))  |
	   (PINE&(1<<6) ? 0 : (1<<0));
}

/* Row pin configuration
 * row: 0   1   2   3   4
 * pin: D0  D1  D2  D3  D5
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRF  &= ~0b11110011;
    PORTF &= ~0b11110011;
}

static void select_row(uint8_t row)
{
    // Output low(DDR:1, PORT:0) to select
    switch (row) {
        case 0:
            DDRF  |= (1<<0);
            PORTF &= ~(1<<0);
            break;
        case 1:
            DDRF  |= (1<<1);
            PORTF &= ~(1<<1);
            break;
        case 2:
            DDRF  |= (1<<4);
            PORTF &= ~(1<<4);
            break;
        case 3:
            DDRF  |= (1<<5);
            PORTF &= ~(1<<5);
            break;
        case 4:
            DDRF  |= (1<<6);
            PORTF &= ~(1<<6);
            break;
        case 5:
            DDRF  |= (1<<7);
            PORTF &= ~(1<<7);
            break;

    }
Keymap_poker.c
#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KEYMAP(ESC,  F1,   F2,   F3,   F4,   F5,   F6,   F7,   F8,   F9, F10, F11, F12, PSCR, SLCK, PGUP, \
	GRV,  1,   2,   3,   4,   5,   6,   7,   8,   9,   0, NUBS, EQL, BSPC,PGDN, \
	TAB, Q, W, E, R, T, Y, U, I , O ,P, LBRC, RBRC, ENT, HOME, \
	CAPS, A, S, D, F, G, H, J, K, L, O, SCLN, QUOT, END, \
	LSFT, BSLS, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, UP, \
	LCTL, FN1, LALT, SPC, RALT, FN2, LEFT, RIGHT, DOWN),
};

const uint16_t PROGMEM fn_actions[] = {

};

User avatar
MrMen

16 Jul 2016, 21:45

Hi guys. Sorry Salt it's not an answer but another question about TMK.

Actually I have a HHKB with the awesome Bluetooth version of Hasu. I'd like to use actionmap with it. I found some info about it with AEK, but I'm absolutely not able to use it with Makefile.rn42.

I think my files are ok excepting the Makefile. Does anybody here have an idea about this ? Any hints would be great;-)

User avatar
hasu

18 Jul 2016, 01:52

MrMen wrote: Hi guys. Sorry Salt it's not an answer but another question about TMK.

Actually I have a HHKB with the awesome Bluetooth version of Hasu. I'd like to use actionmap with it. I found some info about it with AEK, but I'm absolutely not able to use it with Makefile.rn42.

I think my files are ok excepting the Makefile. Does anybody here have an idea about this ? Any hints would be great;-)
Try this patch and I didn't test it well but it compiles at least.

You can use it like this.

Code: Select all

$ make -f Makefile.rn42 KEYMAP=<your_actionmap>

Code: Select all

iff --git a/keyboard/hhkb/Makefile.rn42 b/keyboard/hhkb/Makefile.rn42
index 8cb4435..e913b4c 100644
--- a/keyboard/hhkb/Makefile.rn42
+++ b/keyboard/hhkb/Makefile.rn42
@@ -49,8 +49,7 @@ TARGET_DIR = .
 
 
 # List C source files here. (C dependencies are automatically generated.)
-SRC += keymap_common.c \
-       matrix.c \
+SRC += matrix.c \
        led.c
 
 CONFIG_H = config_rn42.h
@@ -121,13 +120,19 @@ NKRO_ENABLE = yes         # USB Nkey Rollover
 #
 # Keymap file
 #
+ifdef ACTIONMAP_ENABLE
+    KEYMAP_FILE = actionmap
+else
+    KEYMAP_FILE = keymap
+    SRC := keymap_common.c $(SRC)
+endif
 ifdef KEYMAP
-    SRC := keymap_$(KEYMAP).c $(SRC)
+    SRC := $(KEYMAP_FILE)_$(KEYMAP).c $(SRC)
 else
     ifdef HHKB_JP
-       SRC := keymap_jp.c $(SRC)
+       SRC := $(KEYMAP_FILE)_jp.c $(SRC)
     else 
-       SRC := keymap_hhkb.c $(SRC)
+       SRC := $(KEYMAP_FILE)_hhkb.c $(SRC)
     endif
 endif
 
diff --git a/keyboard/hhkb/Makefile.rn42.actionmap b/keyboard/hhkb/Makefile.rn42.actionmap
new file mode 100644
index 0000000..aa35f6c
--- /dev/null
+++ b/keyboard/hhkb/Makefile.rn42.actionmap
@@ -0,0 +1,2 @@
+ACTIONMAP_ENABLE = yes # Use 16bit action codes in keymap instead of 8bit keycodes
+include Makefile

User avatar
MrMen

19 Jul 2016, 13:20

Oh Yeah ! Thank you hasu it's working.
Actually, I had few errors in my config file, I debugged all and now with your patch it's ok.

Huge thank you for the answer, the firmware and the hhkb card ;-)

User avatar
kekstee

20 Jul 2016, 12:00

I set up my left shift to be a modifier in order to map shift+esc to GRV. Now, this works for typing, but in games the keyboard won't carry pressed keys over between layer changes. Which means for example I would have to press a movement key again for it to register after pressing shift.

Code: Select all

[1] = ACTION_LAYER_MODS(3, MOD_LSFT)
I assume this is deeply rooted in how layers are handled and difficult to change, but I wonder if it even can be fixed.

User avatar
hasu

21 Jul 2016, 02:47

It is limitation of current keymap system, it clears holding keys(except for modifiers) when layers switching occurs. Its purpose is to prevent key stuck problem.

I have a plan to renew the keymap framework but it will be left alone for a while. Not sure but I guess QMK may resolve this problem, try it with this option enabled.
https://github.com/jackhumbert/qmk_firm ... -modifiers

kitten_paw

08 Aug 2016, 22:35

I am trying to work out a way to bind Ctrl+left click to a key on my mouse layer.

So far I have this in fn_actions:

Code: Select all

    [10] = ACTION_FUNCTION_TAP(CTRL_CLICK)
where CTRL_CLICK is part of an enum.
The relevant part of action_function looks like this:

Code: Select all

case CTRL_CLICK:
    mousekey_clear();
    register_mods(MOD_BIT(KC_LCTL));
    send_keyboard_report();
    mousekey_on(KC_BTN1);
    mousekey_send();
    mousekey_off(KC_BTN1);
    mousekey_send();
    unregister_mods(MOD_BIT(KC_LCTL));
    send_keyboard_report();
    break;
This does not work, hence this post XD. I tried this in a text editor, and when this code is executed, the resulting behavior is as if I had done CTRL+ left double-click. Doing this in Chrome, where ctrl+left click would open a link in a new tab, the link simply opens in the same tab. This is apparently not really consistent, so I either need help debugging this, or maybe somebody can spot my mistake by looking at the code snippets.

User avatar
hasu

08 Aug 2016, 23:53

kitten_paw wrote: I am trying to work out a way to bind Ctrl+left click to a key on my mouse layer.

So far I have this in fn_actions:

Code: Select all

    [10] = ACTION_FUNCTION_TAP(CTRL_CLICK)
where CTRL_CLICK is part of an enum.
The relevant part of action_function looks like this:

Code: Select all

case CTRL_CLICK:
    mousekey_clear();
    register_mods(MOD_BIT(KC_LCTL));
    send_keyboard_report();
    mousekey_on(KC_BTN1);
    mousekey_send();
    mousekey_off(KC_BTN1);
    mousekey_send();
    unregister_mods(MOD_BIT(KC_LCTL));
    send_keyboard_report();
    break;
This does not work, hence this post XD. I tried this in a text editor, and when this code is executed, the resulting behavior is as if I had done CTRL+ left double-click. Doing this in Chrome, where ctrl+left click would open a link in a new tab, the link simply opens in the same tab. This is apparently not really consistent, so I either need help debugging this, or maybe somebody can spot my mistake by looking at the code snippets.
It would be helpful to see how mouse and key events occur actullay with tool like 'xev' or something. But my wild guess is it needs delay between key and mouse send functions.

kitten_paw

11 Aug 2016, 08:26

hasu wrote: It would be helpful to see how mouse and key events occur actullay with tool like 'xev' or something. But my wild guess is it needs delay between key and mouse send functions.
I added a delay, but it did not help (at least not by itself, see below). Still, your idea of using xev was a good one. By checking the xev output I could verify that one keypress did indeed send Ctrl+left click twice. The solution was to think more before I write half-assed code: I did not check record->event.pressed, so I guess I was sending the keycodes upon press and release. This solution worked in the text editor, but in Chrome the link still wasn't opened in a new tab. I then added a few milliseconds of delay between each keypress which solved this problem as well.

Thanks for the help and for making this awesome firmware available.

User avatar
Cortes

16 Nov 2016, 01:19

Is it possible to control leds from tmk? Turn on/off, adjust brightness ...

Post Reply

Return to “Workshop”