pacocoursey / cmdk

Fast, unstyled command menu React component.
https://cmdk.paco.me
MIT License
9.98k stars 287 forks source link

Google Chrome & Windows - `CTRL+K` forces a google search #288

Closed Hacksore closed 4 months ago

Hacksore commented 4 months ago

Hi folks 👋

I was on my windows laptop to fix a smol lil bug in my app. As a chronic CMD+K user on macOS (raycast, discord, github, vercel) I was like let me jump to github and pull up the palette only to discover that google HARD CODES CTRL+K to perform a google search 😢.

Figured opening an issue here could help us discover workarounds but at the moment I don't have anything to suggest.

https://support.google.com/chrome/thread/235515391/can-i-turn-of-the-ctrl-k-for-search?hl=en https://support.google.com/chrome/answer/157179?hl=en&co=GENIE.Platform%3DDesktop#zippy=%2Caddress-bar-shortcuts:~:text=Ctrl%20%2B%20k%20or%20Ctrl%20%2B%20e

Hacksore commented 4 months ago

Update, this is able to be event.preventDefault()'d!

MVP test code and I was able to not perform a Google search. Not sure why many sites are not adding this but and if it has downsides but this is the solution.

document.addEventListener("keydown", (event) => {
  if (event.ctrlKey && event.key === "k") {
    console.log("Ctrl+K pressed!");
    event.preventDefault(); // Prevent doing a google search
  }
});

image

Hacksore commented 4 months ago

Opened this to track the fix on github https://github.com/orgs/community/discussions/133328.

🙏