How to toggle the Control Key Function using Magic Mouse

I'm new so this might be a noob question but I want to configure a shortcut that will permanently hold Control until I use the same (or different) short cut to disable it. I want to do this on the Magic Mouse specifically because if there is a way to toggle it without me needing to hold it down, I can pinch zoom by scrolling up and down as there's a setting that activates pinch to zoom if the control key is pressed in Accessibility. Lots of words, basically how do I toggle control to always on using a Magic Mouse?

1 Like

Hi @The_Man_27, here is an AppleScript which you can enable and disable with a mouse gesture:

For macOS Catalina:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


--tell application "System Events"
--  set wasRunning to count (processes whose name is "System Preferences")
--end tell

set wasRunning to (application "System Preferences" is running) -- returns true/false

tell application "System Preferences"
	reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
	--delay 1
	set isShowing to false
	repeat until isShowing
		delay 0.1
		set isShowing to exists (anchor "keyboardTab" of pane "com.apple.preference.keyboard")
	end repeat
	
end tell
tell application "System Events" to tell process "System Preferences"
	set theCheckbox to checkbox 1 of tab group 1 of window 1
	click theCheckbox
	set checkboxStatus to value of theCheckbox as boolean
	if checkboxStatus is false then
		display notification "Function Keys Off"
	else
		display notification "Function Keys On" sound name "tink" #ADD sound
		
	end if
end tell

--if wasRunning = 0 then
--  quit application "System Preferences"
--end if

if wasRunning is false then
	quit application "System Preferences"
end if

For macOS Big Sur:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


--tell application "System Events"
--  set wasRunning to count (processes whose name is "System Preferences")
--end tell

set wasRunning to (application "System Preferences" is running) -- returns true/false

tell application "System Preferences"
	reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
	--delay 1
	set isShowing to false
	repeat until isShowing
		delay 0.1
		set isShowing to exists (anchor "keyboardTab" of pane "com.apple.preference.keyboard")
	end repeat
	
end tell
tell application "System Events" to tell process "System Preferences"
	set theCheckbox to checkbox 1 of tab group 1 of window 1
	click theCheckbox
	set checkboxStatus to value of theCheckbox as boolean
	if checkboxStatus is false then
		display notification "Function Keys Off"
	else
		display notification "Function Keys On" sound name "tink" #ADD sound
		
	end if
end tell

--if wasRunning = 0 then
--  quit application "System Preferences"
--end if

if wasRunning is false then
	quit application "System Preferences"
end if

I myself use the free app Fluor for this. Since I can single figure the apps with this. Saves me a mouse gesture or shortcut :wink:

@appleianer Have to admit, I’m impressed. Almost 100% of scripts involving System Events scripting the UI, or System Preferences to access settings, are terribly written. Yours is good. The comments make it hard to read, and you definitely commented out the right bits (I’d just delete them, personally). But I wish everyone wrote scripts that demonstrate how to do stuff properly as you’ve done, rather than the first thing that works.

Sadly, it isn’t what the OP asked for, he just used the word Function inappropriately and capitalised the first letter, which didn’t aid clarify.

He’s basically looking to press and hold .


@The_Man_27 I don’t have a computer to test, but I think these handlers should let you dictate the state of :

to ctrl()
    tell application id "com.apple.SystemEvents" to key down control
end ctrl

to unctrl()
    tell application id "com.apple.SystemEvents" to key up control
end unctrl
1 Like