Qalculate / qalculate-gtk

Qalculate! GTK+ UI
https://qalculate.github.io/
GNU General Public License v2.0
945 stars 68 forks source link

Set Keyboard Key #182

Open numeralnathan opened 4 years ago

numeralnathan commented 4 years ago

My keyboard has a calculator key. When I press it, the configured calculator starts. During the installation of Qalculate, please configure the calculator key to open Qalculate.

foreachthing commented 4 years ago

You should be able to set your key to any other exe. What keyboard are you using? You could replace Windows's calc with Qalculate... This has nothing to do with Qalculate.

numeralnathan commented 4 years ago

I can manually set my key to any exe. This is a manual step that I would like Qalculate's installer to automatically do.

hanna-kn commented 4 years ago

I know how to specify a shortcut hotkey in the installer, but I do not know how to specifically configure the calculator key.

Gaurav-Original-ClassicShellTester commented 3 years ago

If you have Windows 7 32-bit in a VM, you can try to install XP's Microsoft PowerToy TweakUI 2.10 on it. TweakUI has a feature to tweak the Registry to configure hardware keys like the Calculator key to launch any program. Maybe you'll find the key where it's writing. I suspect the value might be at ScanCode value at HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout

foreachthing commented 3 years ago

I just got a new keyboard with a calculator key. So, here's what I did to make Q! my default calculator (I followed the steps from here:

  1. open regedit

  2. go to: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\calc.exe (if it doesn't exist, you'll need to create that key first)

  3. add new string value: "Debugger"

  4. create a batch file (name it start_qalculate.bat) with this content below and save it in an easy to remember place:

    echo off
    echo Starting Qalculate!
    START "" "C:\Program Files\Qalculate\qalculate.exe"
  5. add the path to the batch file as "value data" in "Debugger" (registry): c:\PATH\TO\start_qalculate.bat

Note: You cannot add the path to the exe directly, as the debugger will append its path as parameter to qalculate.exe. This way you'll end up with the path written as equation inside Qalculate at startup.

Happy trails!

Gaurav-Original-ClassicShellTester commented 3 years ago

Well this method works but it eliminates your ability entirely to start Windows Calculator. The HID/hotkey method does not replace Windows Calculate with Qalculate!. It only binds the program you specify to the Calculator hotkey on the keyboard.

foreachthing commented 3 years ago

Well this method works but it eliminates your ability entirely to start Windows Calculator.

False. You can still start Windows Calculator via Start menu.

It only binds the program you specify to the Calculator hotkey on the keyboard.

True. That was the OP's question/request.

foreachthing commented 3 years ago

Just found another way, without additional batch file:

  1. open regedit
  2. surf to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18
  3. add string named "ShellExecute"
  4. give it the value of c:\Program Files\Qalculate\qalculate.exe

This works on my Dell KB522.

EDIT: make sure you remove this key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\calc.exe as it would override the command.

Source: Reprogramming-my-Dell-Keyboard-Hot-Keys

Use RegEdit to open the registry and navigate to: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey The subkeys here (on my Dell Enh Wireless KB) correspond to a subset of the 'programmable' keys. They are:

  • 15 - Mail,
  • 16 - Musical notes/Ausio key which is by default runs mmkey.exe, but I just substituted wmplayer in the ShellExecute subkey to run MS media player,
  • 17 - My computer,
  • 18 - Calc.exe,
  • 7 - web browser. Hope this helps.
Gaurav-Original-ClassicShellTester commented 3 years ago

Well I finally had the time to use TweakUI on Windows 7 to find out using Sysinternals tools which registry key it is setting to remap the Calculator key on the keyboard and it turns out it is an EXPLORER SHELL feature. Set this and log out or restart Explorer.exe and the Calculator key on your keyboard will launch Qalculate!

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18] "ShellExecute"="\"C:\Program Files\Qalculate\qalculate.exe\" "

Edit: foreachthing beat me to it.

Gaurav-Original-ClassicShellTester commented 3 years ago

Just found another way, without additional batch file:

  1. open regedit
  2. surf to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18
  3. add string named "ShellExecute"
  4. give it the value of c:\Program Files\Qalculate\qalculate.exe

This works on my Dell KB522.

EDIT: make sure you remove this key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\calc.exe as it would override the command.

Source: Reprogramming-my-Dell-Keyboard-Hot-Keys

Use RegEdit to open the registry and navigate to: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey The subkeys here (on my Dell Enh Wireless KB) correspond to a subset of the 'programmable' keys. They are:

  • 15 - Mail,
  • 16 - Musical notes/Ausio key which is by default runs mmkey.exe, but I just substituted wmplayer in the ShellExecute subkey to run MS media player,
  • 17 - My computer,
  • 18 - Calc.exe,
  • 7 - web browser. Hope this helps.

If you set the Debugger value in Image File Execution Options, all ways to open Windows Calc.exe will open Qalculate so don't call me false, you are false. The ShellExecute key on the other hand will correctly map Calculator key on the keyboard to Qalculate without taking away ability to launch Windows Calc.exe

foreachthing commented 3 years ago

If you set the Debugger value in Image File Execution Options, all ways to open Windows Calc.exe will open Qalculate so don't call me false, you are false.

My appologies! My computer did what I wrote. I don't know why yours didn't do the same.

Gaurav-Original-ClassicShellTester commented 3 years ago

If you set the Debugger value in Image File Execution Options, all ways to open Windows Calc.exe will open Qalculate so don't call me false, you are false.

My appologies! My computer did what I wrote. I don't know why yours didn't do the same.

If you are using old Windows 7 Calculator on Windows 10, the binary may be named Calc1.exe and not Calc.exe which is why I am guessing your computer did what it did. 😊

numeralnathan commented 3 years ago

The Debugger value in the registry worked for me. Setting HKEY_*\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18 did not work for me.

Here is the reg command to set the Debugger value. I added this to my batch file that installs all of my software via Chocolatey and configures most of my software... for the next time I upgrade my laptop and need to install everything.

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\calc.exe" /v Debugger /t REG_SZ /f /d "C:\Documents\Library\BatchFiles\Qalculate\Start Qalculate.bat"

Gaurav-Original-ClassicShellTester commented 3 years ago

The Debugger value will work instantly. The other Appkey tweak requires logging off or restart or closing all instances of Explorer.exe and then restarting the Explorer.exe process. The Debugger tweak will prevent the original Calc.exe from working unless it is renamed to some other binary e.g. Calc1.exe or WinCalc.exe. It basically replaces Calc with Qalculate!. The App key method will only affect the dedicated Calculator key that some keyboards have to launch the Calculator. I don't see why there is confusion as the two work completely differently.

cousteaulecommandant commented 1 year ago

TL;DR: Maybe the Windows version of Qalculate should add support for the calculator: URL.


You can choose the default calculator in Windows by going to Settings > Apps > Default apps > Choose default apps by protocol > CALCULATOR (URL:calculator) and selecting a valid calculator app from the list. However, the only app in that list is the Windows calculator; unfortunately you can't choose Qalculate. I understand that this is because Windows only lists apps that support the calculator: URI scheme, which the Windows calculator does (if you type calculator: in Chrome's or Edge's URL bar, it'll ask you if you want to open the Calculator app). So, the way to add Qalculate to that list is probably to somehow "register" it as supporting the calculator: URL protocol when it is installed, which I have no idea how it's done; that way users will be able to set it as the default calculator. The installer could also ask if you want to set Qalculate as the default calculator since this option is not easy to find in Settings.

(Maybe I should open a new issue for this, or at least the title of this one should be changed to clarify that this is for Windows, because for Linux this is trivial to change)

numeralnathan commented 1 year ago

Settings > Apps > Default apps > Choose default apps by protocol does not exist on Windows 11 version 22H2 build 22621.1555. Settings > Apps > Default apps > Choose defaults by link type exists but not CALCULATOR.

cousteaulecommandant commented 1 year ago

Must be a Windows 10 thing then, weird. Perhaps Windows 11 has another way to let you choose what the calculator key does (without modifying the registry).