Basically, what I want to achieve is the second example here:

As an example, we can make the space bar work as an additional ctrl key when held (similar to Space2ctrl) with the following sequence of commands.

— https://github.com/alols/xcape#examples

Or here:

This little hack for X turns the spacebar key into another control key when used in combination. When used alone, it behaves like the ordinary space bar on the key release event. Especially useful with Emacs.

— https://github.com/r0adrunner/Space2Ctrl

So:

  • Space+x should send Command+X,
  • while Space pressed and released should send one space character.

Solution 1:

  1. Install Karabiner.

  2. Place this in your private.xml (~/Library/Application Support/Karabiner)

    <item>
            <name>Use Space as Command modifier</name>
            <identifier>private.space_command_key</identifier>
            <autogen>__KeyOverlaidModifier__ KeyCode::SPACE, KeyCode::COMMAND_L, KeyCode::SPACE</autogen>
    </item> 
    

    It goes in between the <root> and </root> tags.

    If you want to remap it to Control instead, you can change the KeyCode::COMMAND_L to KeyCode::CONTROL_L.

  3. Launch Karabiner, press ⟳ ReloadXML, and check the box