Alt key pressed all the time

Hello, it’s been a while since I requested help.
While using the OS, the Alt key is seemingly pressed when the key on the keyboard is not. this issue started appearing appearing last weekend (26 - 27.04).

Biggest issue with this problem is that it’s inconsistent and I don’t know the steps for reproduction but I’m pretty sure it can’t be my membrane keyboard dying.

Following is my current configuration.nix

{ config, lib, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./modules/env.nix
      #./modules/wallpaper-engine-kde-plugin.nix
    ];


   hardware.nvidia = {
#     package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
#       version = "565.57.01";
#       sha256_64bit = "sha256-buvpTlheOF6IBPWnQVLfQUiHv4GcwhvZW3Ks0PsYLHo=";
#       sha256_aarch64 = "sha256-aDVc3sNTG4O3y+vKW87mw+i9AqXCY29GVqEIUlsvYfE=";
#       openSha256 = "sha256-/tM3n9huz1MTE6KKtTCBglBMBGGL/GOHi5ZSUag4zXA=";
#       settingsSha256 = "sha256-H7uEe34LdmUFcMcS6bz7sbpYhg9zPCb/5AmZZFTx1QA=";
#       persistencedSha256 = "sha256-hdszsACWNqkCh8G4VBNitDT85gk9gJe1BlQ8LdrYIkg=";
#     };

    package = config.boot.kernelPackages.nvidiaPackages.beta;

    # The nvidia-settings build is currently broken due to a missing
    # vulkan header; re-enable whenever
    # 0384602eac8bc57add3227688ec242667df3ffe3the hits stable.
    nvidiaSettings = true;

    modesetting.enable = true;
    # Power management is required to get nvidia GPUs to behave on
    # suspend, due to firmware bugs. Aren't nvidia great?
    powerManagement.enable = true;
    open = true;
  };

  # Bootloader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.systemd-boot.configurationLimit = 10;

  # Kernel
  #boot.kernelPackages = pkgs.linuxPackages_latest;
  boot.kernelPackages = pkgs.linuxPackages_6_12;
  #boot.blacklistedKernelModules = [ "amdgpu" ];
  boot.kernelParams = 
  [
    "amd_iommu=on"

    # RTX 2070 (VGA, Audio, USB, Serial bus)
    "vfio-pci.ids=10de:1f02,10de:10f9,10de:1ada,10de:1adb"

    # Strix GTX 980 Ti
    #"vfio-pci.ids=10de:17c8,10de:0fb0"

    # slim HD 5450 650M 1GB DDR3
    #"vfio-pci.ids=1002:68f9,1002:aa68,"
    
    # thicc HD 4870 1GB DDR5
    #"vfio-pci.ids=1002:9440,1002:aa30,"
  ];
  boot.kernelModules = [
    "vfio_virqfd"
    "vfio_pci"
    "vfio_iommu_type1"
    "vfio"
    "nct6775"
    "linuxKernel.packages.linux_6_11.apfs"
  ];
  boot.extraModprobeConfig = ''
    options v4l2loopback devices=1 video_nr=1 card_label="OBS Cam" exclusive_caps=1
    options vfio-pci ids=1002:68f9,1002:aa68
  '';
  #boot.initrd.kernelModules = [ "nvidia" "nvidia_drm" "nvidia_uvm" "nvidia_modeset" ];
  boot.extraModulePackages = with config.boot.kernelPackages; [
    v4l2loopback
  ];



  networking.hostName = "nixos"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Enable networking
  networking.networkmanager.enable = true;

  # Set your time zone.
  time.timeZone = "Europe/Berlin";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "de_DE.UTF-8";
    LC_IDENTIFICATION = "de_DE.UTF-8";
    LC_MEASUREMENT = "de_DE.UTF-8";
    LC_MONETARY = "de_DE.UTF-8";
    LC_NAME = "de_DE.UTF-8";
    LC_NUMERIC = "de_DE.UTF-8";
    LC_PAPER = "de_DE.UTF-8";
    LC_TELEPHONE = "de_DE.UTF-8";
    LC_TIME = "de_DE.UTF-8";
  };

   services.udev.extraRules = ''
   # Pen Tablet
   SUBSYSTEM=="usb", ATTRS{product}=="XP-Pen Artist 12 (2nd Gen)", ATTRS{idProduct}=="094a", ATTRS{idVendor}=="28bd", MODE="0660", GROUP="plugdev"
   KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0666", GROUP="plugdev"

   # Arduino
   KERNEL=="ttyUSB*", SUBSYSTEM=="tty", SUBSYSTEMS=="usb-serial", ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86", MODE="0666", GROUP="plugdev"
   #SUBSYSTEMS=="usb", ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86", MODE="0666", GROUP="plugdev"
   '';

  # file system shenanigans
  fileSystems."/mnt/Games" =
  {
    device = "/dev/disk/by-uuid/9226e50e-fc7b-4a95-baac-a59b1d779899";
    fsType = "ext4";
    options =
    [
      "users"
      "nofail"
      "x-gvfs-show"
      "exec"
    ];
    label = "Games";
  };

  # fileSystems."/mnt/SeagateBarracuda" =
  # {
  #   device = "/dev/disk/by-uuid/1b78ca3b-618f-496f-8a6e-d4e575f5d84b";
  #   fsType = "ext4";
  #   options =
  #   [
  #     "users"
  #     "nofail"
  #     "x-gvfs-show"
  #     "exec"
  #   ];
  #   label = "Seagate Barracuda";
  # };

  # fileSystems."/mnt/HGST" =
  # {
  #   device = "/dev/disk/by-uuid/a18e9a89-3b84-4bc0-85fc-5828bd1e7342";
  #   fsType = "ext4";
  #   options =
  #   [
  #     "users"
  #     "nofail"
  #     "x-gvfs-show"
  #     "exec"
  #   ];
  #   label = "HGST";
  # };

  fileSystems."/mnt/WinVM" =
  {
    device = "/dev/disk/by-uuid/3199b99a-c2f5-42c7-b41e-11d83b97da4d";
    fsType = "ext4";
    options =
    [
      "users"
      "x-gvfs-show"
      "exec"
    ];
    label = "WinVM";
  };

  fileSystems."/mnt/SeagateIronWolf" =
  {
    device = "/dev/disk/by-uuid/376062a8-c9db-4f8b-b625-52448bee483d";
    fsType = "ext4";
    options =
    [
      "users"
      "nofail"
      "x-gvfs-show"
      "exec"
    ];
    label = "Sex Drive";
  };

  fileSystems."/mnt/smb" = {
    device = "//192.168.0.16/nika";
    fsType = "cifs";
    options = let
      automount_opts = "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s,user,users";
    in ["${automount_opts},credentials=/home/nika/.dotfiles/smb-secrets,uid=1000,gid=100"];
  };



  # fuck nvidia
  #services.xserver.videoDrivers = ["nvidia"];
  hardware.graphics = {
    enable = true;
    enable32Bit = true;
  };
#   hardware.nvidia = {
#     #package = config.boot.kernelPackages.nvidiaPackages.latest;
#     open = false;
#     #nvidiaSettings = true;
#     modesetting.enable = true;
#     powerManagement.enable = true;
#   };
#
#   #hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.latest;
#    hardware.nvidia = {
#      package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
#        version = "560.35.03";
#        sha256_64bit = "sha256-8pMskvrdQ8WyNBvkU/xPc/CtcYXCa7ekP73oGuKfH+M=";
#        sha256_aarch64 = "sha256-s8ZAVKvRNXpjxRYqM3E5oss5FdqW+tv1qQC2pDjfG+s=";
#        openSha256 = "sha256-/32Zf0dKrofTmPZ3Ratw4vDM7B+OgpC4p7s+RHUjCrg=";
#        settingsSha256 = "sha256-kQsvDgnxis9ANFmwIwB7HX5MkIAcpEEAHc8IBOLdXvk=";
#        persistencedSha256 = "sha256-E2J2wYYyRu7Kc3MMZz/8ZIemcZg68rkzvqEwFAL3fFs=";
#      };
#      nvidiaSettings = false;
#    };

  # Enable the X11 windowing system.
  # You can disable this if you're only using the Wayland session.
  services.xserver.enable = true;

  # Enable Wayland windowing system
#  services.displayManager.sddm.wayland.enable = true;

  # Enable the KDE Plasma Desktop Environment.
  services.displayManager.sddm.enable = true;
  services.displayManager.sddm.wayland.enable = true;
  services.desktopManager.plasma6.enable = true;

  # Configure keymap in X11
  services.xserver = {
    xkb.layout = "us";
    xkb.variant = "";
  };

  # Enable CUPS to print documents.
  services.printing.enable = true;

  # Bluetooth
  hardware.bluetooth = {
    enable = true;
    powerOnBoot = true;
  };

  hardware.sane = {
    enable = true;
    extraBackends = [ pkgs.sane-airscan ];
  };

  hardware.opentabletdriver.enable = true;

  # turn off the daemon service - it's borked afaik so for now I'll just use autostart until there either there's a fix or I'll fix it
  hardware.opentabletdriver.daemon.enable = true;

  services.hardware.openrgb.enable = true;

  #REDACTED

  services.avahi.enable = true;
  services.avahi.nssmdns4 = true;

  # Enable sound with pipewire.
#   hardware.pulseaudio = {
#     enable = true;
#     extraConfig = "load-module module-equalizer-sink\nload-module module-dbus-protocol";
#   };
#   security.rtkit.enable = true;
  security.polkit.enable = true;
  # By default, NixOS uses Pipewire. Below is the default setting
   services.pipewire = {
     enable = true;
     alsa.enable = true;
     alsa.support32Bit = true;
     pulse.enable = true;
#     extraConfig.pipewire =
#      {
#         "10-null-sink" = {
#           context.objects = [
#             { factory = "adapter";
#               args = {
#                 factory.name = "support.null-audio-sink";
#                 node.name = "my-sink";
#                 media.class = "Audio/Sink";
#                 audio.position = [ "FL" "FR" "FC" "LFE" "RL" "RR" ];
#                 monitor.channel-volumes = true;
#                 monitor.passthrough = true;
#                 adapter.auto-port-config = {
#                   mode = "dsp";
#                   monitor = true;
#                   position = "preserve";
#                 };
#               };
#             }
#           ];
#         };
#      };
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  # TLP Power management
#   services.tlp = {
#     enable = true;
#     settings = {
#       CPU_SCALING_GOVERNOR_ON_BAT="performance";
#       CPU_SCALING_GOVERNOR_ON_AC="performance";
#
#       # 100 is max
#       CPU_MAX_PERF_ON_BAT=100;
#       CPU_MAX_PERF_ON_AC=100;
#     };
#   };

  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  users.groups.plugdev = {};

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.nika = {
    isNormalUser = true;
    description = "nika";
    extraGroups = [ "networkmanager" "wheel" "libvirtd" "wireshark" "openrazer" "scanner" "lp" "plugdev" ];
    packages = with pkgs; [
      kdePackages.kate
    #  thunderbird
    ];
  };

  services.davfs2.enable = true;

  services.samba.enable = true;

  #services.monero.enable = true;

#   services.xmrig = {
#     enable = true;
#     settings = {
#       autosave = true;
#       cpu = true;
#       opencl = false;
#       cuda = true;
#       pools = [
#         {
#           url = "pool.supportxmr.com:443";
#           user = "your-wallet";
#           keepalive = true;
#           tls = true;
#         }
#       ];
#     };
#   };

  # Install firefox.
  programs.firefox.enable = true;

  # Install Steam
  programs.steam = {
    enable = true;
    remotePlay.openFirewall = true; # Open ports in the firewall for Steam Remote Play
    dedicatedServer.openFirewall = true; # Open ports in the firewall for Source Dedicated Server
  };

  # install git
  programs.git = {
    enable = true;
  };

  programs.wireshark = {
    enable = true;
  };

  programs.coolercontrol.enable = true;

  hardware.openrazer.enable = true;

  #nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
  #  "steam"
  #  "steam-original"
  #  "steam-run"
  #];

  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;

  # when i know what needs these packages, remove this!! insecure af but I need to update the system
  # 02.12.24 - error: Package ‘x’ in /nix/store/ljk3wvwqqzbmz0pys49ii18qmsi5aibc-source/pkgs/development/compilers/dotnet/build-dotnet.nix:212 is marked as insecure, refusing to evaluate.
  # nixpkgs.config.permittedInsecurePackages = [
  #   "dotnet-runtime-6.0.36"
  #   "dotnet-sdk-wrapped-6.0.428"
  #   "dotnet-sdk-6.0.428"
  #   "dotnet-runtime-wrapped-6.0.36"
  # ];


  # libvirtdeez nuts AAAAAAAAAAAAaa
  virtualisation.libvirtd = {
    enable = true;
    qemu = {
      package = pkgs.qemu_kvm;
      runAsRoot = true;
      swtpm.enable = true;
      ovmf = {
        enable = true;
        packages = [(pkgs.OVMF.override {
          secureBoot = true;
          tpmSupport = true;
        }).fd];
      };
      vhostUserPackages = [
        pkgs.virtiofsd
      ];
    };
  };

  virtualisation.docker.enable = true;

  # Automatically delete generations older than 30 days every week
  nix.gc = {
    automatic = true;
    dates = "weekly";
    options = "--delete-older-than 30d";
  };

 # specialisation."VFIO".configuration = {
  #  system.nixos.tags = [ "with-vfio" ];
  # vfio.enable = true;
  #};

  # List packages installed in system profile. To search, run:
  # $ nix search wget

  #let
  #  nvidiaEnabled = lib.elem "nvidia" config.services.xserver.videoDrivers;
  #  wallpaper-engine-kde-plugin = "./modules/wallpaper-engine-kde-plugin.nix"
  #in

  environment.systemPackages =
    #let
    #  nvidiaEnabled = lib.elem "nvidia" config.services.xserver.videoDrivers;
    #  wallpaper-engine-kde-plugin = "./modules/wallpaper-engine-kde-plugin.nix"
    #in
    #(
    with pkgs; [
  #  vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
  #  wget
    librewolf
    lshw
    vlc
    wineWowPackages.stable
    winetricks
    gparted
    ntfs3g
    kdePackages.yakuake
    htop
    _1password-gui
    vencord
    spotify
    obs-studio
    cowsay
    kdePackages.kalarm
    nextcloud-client
    pciutils
    exfat
    wireshark
    exfatprogs
    cifs-utils
    kdePackages.kdenlive
    #glaxnimate
    hyfetch
    openrazer-daemon
    polychromatic
    libsForQt5.skanlite
    #gnome.simple-scan
    openrgb-with-all-plugins
    popsicle
    #libsForQt5.xp-pen-g430-driver
    krita
    #libsForQt5.xp-pen-deco-01-v2-driver
    tmuxPlugins.open
    screen
  # linux-wallpaperengine
    signal-desktop
    monero-gui
    qpaeq
    xmrig
    vesktop
    coolercontrol.coolercontrol-gui
    coolercontrol.coolercontrol-ui-data
    lm_sensors
    yt-dlp
    arduino
    usbutils
    audacity
    freerdp3
    remmina
    xclicker
    dotnetCorePackages.dotnet_9.runtime
    icu
    vscode
    qdirstat
    kdePackages.kget
    #kdePackages.kcolorpicker
    #libsForQt5.kcolorpicker
    xcolor
    kdiskmark
    gsmartcontrol
    qpwgraph
    libreoffice
    esptool
    kdePackages.korganizer
    lmms
    dxvk_2
    furmark
    sshfs
    zip
    apfs-fuse
    _7zz
    kdePackages.qtwebsockets
    #python3Full
    #python-qt
    #python312Packages.websockets
    kdePackages.qtwebchannel
    xorg.libxcb
    modrinth-app-unwrapped
    #minecraft
    prismlauncher
    cmake
    kdePackages.k3b
    dvdplusrwtools
    android-tools
    droidcam
    kdePackages.krdc
    power-profiles-daemon
    woeusb
    handbrake
    projectm
    davinci-resolve
    ffmpeg-full
    shotcut
    gsmartcontrol
    podman
    protontricks

    # QEMU stuff
    qemu
    virt-manager
    virt-viewer
    dnsmasq
    vde2
    bridge-utils
    netcat-openbsd
    libguestfs
    libvirt

    # Python
    (python3.withPackages (ps: [
      ps.websockets
      ps.python-qt
    ]))

    # Wallpaper Engine shit
    mpv
    gst_all_1.gst-libav
    #libsForQt5.plasma-framework
    # PLASMA FRAMEWORK IS BORKED!!
    lz4
    glslang
    vulkan-headers
    vulkan-loader
    vulkan-tools
    #libsForQt5.plasma-workspace
    # same with this shit istg
    kdePackages.plasma-workspace
    kdePackages.qtwebengine
    kdePackages.qtbase
    kdePackages.kpackage
    kdePackages.kdeclarative
    kdePackages.libplasma
    kdePackages.qtwebsockets
    kdePackages.qtwebchannel
    kdePackages.qtmultimedia
    kdePackages.qtdeclarative
  ];
  #)
  #++ lib.optionals nvidiaEnabled [
  #  (config.hardware.nvidia.package.settings.overrideAttrs (oldAttrs: {
  #    buildInputs = oldAttrs.buildInputs ++ [ pkgs.vulkan-headers ];
  #  }))
  #];



  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ 11987 ];
  # networking.firewall.allowedUDPPorts = [  ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "24.05"; # Did you read the comment?

  nix.settings.experimental-features = [ "nix-command" "flakes" ];
}

If you think this occurs because of changes in nixos, try rolling back to earlier versions.

I lean more towards this being a hardware problem. Imagine what a few crumbs might do under the keys. Gently whacking the keyboard standing on edge might move the cruft enough to change the behavior. Even better is if you can disassemble and clean it.

I use KDE Plasma 6, and if I disconnect the keyboard the key shouldn’t be pressed, right?
If you hold Right Alt in specific and try to right click on the desktop, no context menu will pop up.
Disconnecting the keyboard didn’t stop the key being pressed interestingly.

Yeah, I would think that disconnecting the keyboard would prevent the system from seeing it at input.

I do not know KDE at all. Are you saying that when you have the keyboard disconnected the mouse clicks behave as if Right Alt is pressed?

What you describe definitely sounds like a software problem. Trying older versions of the OS or nixpkgs ought to help identify which software is doing it. If your boot loader offers old enough versions, using that would be easiest.

You also might find clues with a dive into what has changed in the parts of nixpkgs you use.

It’s such a weird problem. I will try looking into removing some of the packages that I don’t really need anymore and see what happens but for now things are looking fine without changes. It’s frustrating.

Yes, frustratingly weird. I imagine there are many ways this could happen in software.

Do you have “Pen Tablet” attached when it happens? What about an Arduino?

I do not recall if the Alt key from one keyboard can affect the behavior of a second keyboard. That it affects the mouse suggest it probably would affect a second keyboard, which implies the Alt input could be coming from any other device attached.

Do you see the behavior when pressing other keys, or only with the mouse?

Oh actually I was about to comment on that! I have the Open Tablet Driver installed and I currently use a drawing tablet as a second display. I have realized that there is are following devices showing up when executing lshw:

*-input:18
       product: OpenTabletDriver Virtual Artist Tablet
       physical id: 14
       logical name: input51
       logical name: /dev/input/event259
       logical name: /dev/input/mouse6
  *-input:19
       product: OpenTabletDriver Virtual Keyboard
       physical id: 15
       logical name: input52
       logical name: /dev/input/event260

I will try disconnecting the tablet when I encounter this problem again.

1 Like

Looking a bit deeper, I found the devices for the physical tablet itself there as well

  *-input:1
       product: HANVON UGEE Artist 12 (2nd Gen) Mouse
       physical id: 3
       logical name: input1
       logical name: /dev/input/event1
       logical name: /dev/input/mouse0
       capabilities: usb
  *-input:2
       product: HANVON UGEE Artist 12 (2nd Gen) Keyboard
       physical id: 4
       logical name: input2
       logical name: /dev/input/event2
       capabilities: usb

It was in fact the pen tablet. When the problem appeared again, pressing the key on the tablet that I have bound to Alt would stop the Alt from being pressed lol.
Sorry for wasting time but hey, it might help someone.

Not a waste. I learned plenty digging into the problem and had fun doing it. Thanks. :slight_smile:

1 Like