Skip to content

Instantly share code, notes, and snippets.

@ivanstepanovftw
Last active October 24, 2024 02:00
Show Gist options
  • Save ivanstepanovftw/f60327c1b1a8ac2f0ac9fbafda059ad8 to your computer and use it in GitHub Desktop.
Save ivanstepanovftw/f60327c1b1a8ac2f0ac9fbafda059ad8 to your computer and use it in GitHub Desktop.

When I click middle mouse button, and current window name is "Visual Studio Code", instead of middle mouse click do left mouse click and then F12. I am using Fedora.

To achieve this behavior in Fedora, you can use a combination of xdotool and a custom script. Here's a step-by-step guide:

  1. Install xdotool: This is a command-line tool that allows you to simulate keyboard and mouse input.

    sudo dnf install xdotool
  2. Create a script: This script will check the current window name and perform the desired actions.

    Create a new script file, e.g., middle_click_script.sh:

    nano ~/middle_click_script.sh

    Add the following content to the script:

    #!/bin/bash
    
    # Get the active window name
    WINDOW_NAME=$(xdotool getactivewindow getwindowname)
    
    # Check if the active window is "Visual Studio Code"
    if [[ "$WINDOW_NAME" == *"Visual Studio Code"* ]]; then
        # Simulate left mouse click
        xdotool click 1
        # Workaround to add sleep and another click
        sleep 0.1
        xdotool click 1
        # Simulate F12 key press
        xdotool key F12
    else
        # Forward middle mouse click if the active window is not "Visual Studio Code"
        xdotool click 2
    fi

    Save and close the file.

  3. Make the script executable:

    chmod +x ~/middle_click_script.sh
  4. Bind the script to the middle mouse button:

    You can use xbindkeys to bind the middle mouse button to your script. First, install xbindkeys:

    sudo dnf install xbindkeys

    Create a default configuration file for xbindkeys:

    xbindkeys --defaults > ~/.xbindkeysrc

    Edit the configuration file:

    nano ~/.xbindkeysrc

    Add the following line to bind the middle mouse button to your script:

    "bash ~/middle_click_script.sh"
        b:2

    Save and close the file.

  5. Start xbindkeys:

    xbindkeys

    To make sure xbindkeys starts automatically on login, add it to your startup applications. The way to do this might vary depending on your desktop environment.

By following these steps, clicking the middle mouse button while the active window is "Visual Studio Code" will simulate a left mouse click followed by an F12 key press. In all other cases, it will perform the standard middle mouse click.

@ivanstepanovftw
Copy link
Author

fuck it

@ivanstepanovftw
Copy link
Author

suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment