From f017666011787aec780a77301366736cb695867f Mon Sep 17 00:00:00 2001 From: yannickreiss Date: Wed, 18 Dec 2024 12:21:35 +0100 Subject: [PATCH] implement function to collect keystrokes --- lua/macrotool/init.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lua/macrotool/init.lua b/lua/macrotool/init.lua index e525f7f..7a72a1a 100644 --- a/lua/macrotool/init.lua +++ b/lua/macrotool/init.lua @@ -1,7 +1,7 @@ local M = {} local api = vim.api -local +local keystrokes = {} -- Only for debugging if vim == nil then @@ -9,5 +9,21 @@ if vim == nil then end function Macrochain() - vim.print("Hello World!") + vim.print(table.concat(keystrokes, "")) end + +-- @name record_keystroke +-- @param mapped_key +-- @param raw_key +-- @short Add mapped_key to keystrokes +local function record_keystroke(mapped_key, raw_key) + table.insert(keystrokes, mapped_key) + if #keystrokes > 60 then + local temp_keystrokes = {} + for i = 31, #keystrokes do + table.insert(temp_keystrokes, keystrokes[i]) + end + keystrokes = temp_keystrokes + end +end +vim.on_key(record_keystroke)