lencx / ChatGPT

🔮 ChatGPT Desktop Application (Mac, Windows and Linux)
https://nofwl.com
52.36k stars 5.89k forks source link

Feature request: customisable global hotkey to open a new chat in ChatGPT #109

Open heldheld opened 1 year ago

heldheld commented 1 year ago

The idea is to press a global hotkey and then immediately being able to start typing your prompt into ChatGPT for quick and convenient use.

heldheld commented 1 year ago

A different version could be to have a checkbox under the global show/hide shortcut setting to toggle whether a new chat should be opened when using the hotkey to show the window.

virat2010 commented 1 year ago

You can create a JS script that takes this html and uses the click() function on it but I don;t know how because no id tag: <a class="flex py-3 px-3 items-center gap-3 rounded-md hover:bg-gray-500/10 transition-colors duration-200 text-white cursor-pointer text-sm mb-2 flex-shrink-0 border border-white/20"><svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>New chat</a>

dsernst commented 9 months ago

I was able to successfully target the New Chat button with this selector:

document.querySelector('.group.flex.px-2[href="/"]')
dsernst commented 9 months ago

Here's some code GPT4 gave to add this hotkey:

// Add Cmd+N hotkey to start New Chat
document.addEventListener('keydown', (event) => {
  // Check if 'Cmd' and 'N' are pressed together
  if (event.metaKey && event.key === 'n') {
    event.preventDefault() // Prevents default action of the key press

    const $newChatBtn = document.querySelector('.group.flex.px-2[href="/"]')
    if ($newChatBtn) $newChatBtn.click()
  }
})

Added it to my main.js Scripts file (from app's Control Center). Now it works every time 🎉