# Help: Terminal Copy and Paste Macros

**URL:** <https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678>\
**Category:** Programming\
**Tags:** question\
**Created:** [March 9, 2021, 3:06am UTC](https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678 "2021-03-09T03:06:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Infininte](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@Infininte](https://community.keyboard.io/u/Infininte)\
**Post date:** [March 9, 2021, 3:06am UTC](https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678/1 "2021-03-09T03:06:45Z")

</div>

I do a lot of programming on Linux and copy/paste from the Linux terminal is Ctrl + Shift + C / Ctrl + Shift + V. I’d like to map that combination to Fn + C/ Fn + V to simplify the needed keypresses.

I tried to extend the basic Macro function to achieve this, but it didn’t do anything:

```auto
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  switch (macroIndex) {

  case MACRO_VERSION_INFO:
    versionInfoMacro(keyState);
    break;

  case MACRO_ANY:
    anyKeyMacro(keyState);
    break;

  case MACRO_TERMINAL_COPY:
    MACRO(D(LeftControl), D(LeftShift), T(C), U(LeftControl), U(LeftShift));
    break;
  
  case MACRO_TERMINAL_PASTE:
    MACRO(D(LeftControl), D(LeftShift), T(V), U(LeftControl), U(LeftShift));
    break;
  }
  return MACRO_NONE;
}

```

I’m referencing them like this:  
`M(MACRO_TERMINAL_COPY), M(MACRO_TERMINAL_PASTE)`

Can anyone give me advice on how to get this done?

---

<div class="post-metadata">

**Author:** ![Infininte](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@Infininte](https://community.keyboard.io/u/Infininte)\
**Post date:** [March 9, 2021, 3:17am UTC](https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678/2 "2021-03-09T03:17:51Z")

</div>

I just realized that I need to return the MACRO() to get it working. Now it is repeatedly spamming the paste each time I use it. Is there an easy way to stop the spamming?

---

<div class="post-metadata">

**Author:** ![Rom1deTroyes](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/rom1detroyes/32/3352_2.png) [@Rom1deTroyes](https://community.keyboard.io/u/Rom1deTroyes)\
**Post date:** [March 9, 2021, 8:38am UTC](https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678/3 "2021-03-09T08:38:51Z")

</div>

As a lazy guy, I certainly first try to use something like `LCTRL(LSHIFT(Key_C))` or `LCTRL(LALT(Key_V))` directly on the Fn layer, but I may not catch what you need to achieve (I use the mouse middle button shortcut to paste my register).

---

<div class="post-metadata">

**Author:** ![alfalfasprossen](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/alfalfasprossen/32/2101_2.png) [@alfalfasprossen](https://community.keyboard.io/u/alfalfasprossen)\
**Post date:** [March 9, 2021, 10:40am UTC](https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678/4 "2021-03-09T10:40:14Z")

</div>

Macros will fire every cycle while the key is held. You can return `MACRODOWN` instead of `MACRO` instead, which will only fire when the key has just been pressed. Alternatively you can check the keyState yourself for that purpose like `if (keyToggledOn(keyState))`.

But yeah, for such simple cases, you don’t need a macro at all, just define the key with modifiers in the keymap like Rom1deTroyes proposed 😉

---

<div class="post-metadata">

**Author:** ![kajsa.anderson](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/kajsa.anderson/32/346_2.png) [@kajsa.anderson](https://community.keyboard.io/u/kajsa.anderson)\
**Post date:** [March 11, 2021, 1:40am UTC](https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678/5 "2021-03-11T01:40:42Z")

</div>

> [@Rom1deTroyes](#):
>
> As a lazy guy, I certainly first try to use something like `LCTRL(LSHIFT(Key_C))` or `LCTRL(LALT(Key_V))` directly on the Fn layer, but I may not catch what you need to achieve (I use the mouse middle button shortcut to paste my register).

Wow. I don’t know why I never thought of using my key that’s bound to middle mouse button, instead of using Shift+Ins (which is 3 keys, since Ins is on the Fn layer). Thanks!

---

<div class="post-metadata">

**Author:** ![Infininte](https://avatars.discourse-cdn.com/v4/letter/i/e79b87/32.png) [@Infininte](https://community.keyboard.io/u/Infininte)\
**Post date:** [March 11, 2021, 3:13am UTC](https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678/6 "2021-03-11T03:13:50Z")

</div>

> [@Rom1deTroyes](#):
>
> `LCTRL(LSHIFT(Key_C))` or `LCTRL(LALT(Key_V))`

That solved my problem perfectly! Thank you!

---

<div class="post-metadata">

**Author:** ![Rom1deTroyes](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/rom1detroyes/32/3352_2.png) [@Rom1deTroyes](https://community.keyboard.io/u/Rom1deTroyes)\
**Post date:** [March 11, 2021, 11:37am UTC](https://community.keyboard.io/t/help-terminal-copy-and-paste-macros/4678/7 "2021-03-11T11:37:29Z")

</div>

> [@kajsa.anderson](#):
>
> I don’t know why I never thought of using my key that’s bound to middle mouse button

To be honest, I start to use it after having a hard time to understand why my primary register was sometimes pasted instead of my X clipboard… Just discovering the power of the palm key, and the meticulous crafting of the Model01 layers !
