cliclick icon indicating copy to clipboard operation
cliclick copied to clipboard

`fn` modifier does not work with `kp:` action

Open gjherbiet opened this issue 10 months ago • 2 comments

Hello,

I have an issue with cliclick and the fn modifier.

When used with the t: action, the fn modifier works. For instance, this will trigger Notification Center:

% cliclick -m verbose kd:fn t:c ku:fn                         
Hold fn key down
Type: “c”
Release fn key

Even with several modifiers, this works. The following will center the frontmost window:

% cliclick -m verbose kd:ctrl,fn t:c ku:ctrl,fn
Hold ctrl key down
Hold fn key down
Type: “c”
Release ctrl key
Release fn key

However, when used in combination with the kp: action, fn modifier does not seem to work. I wanted to tile the frontmost window to the right half. What occurs is that the window is not tiled and the current desktop switched to the next one (as if fn was not held down):

% cliclick -m verbose kd:ctrl,fn kp:arrow-right ku:ctrl,fn
Hold ctrl key down
Hold fn key down
Press + release arrow-right key
Release ctrl key
Release fn key

I tried the following alternatives, with the same unwanted result:

% cliclick kd:ctrl kd:fn kp:arrow-right ku:fn ku:ctrl
% cliclick kd:fn kd:ctrl kp:arrow-right ku:ctrl ku:fn
% cliclick -w 500 kd:fn kd:ctrl kp:arrow-right ku:ctrl ku:fn

gjherbiet avatar Feb 16 '25 17:02 gjherbiet

I see the same issue. However, the output of your command produces

% cliclick -m verbose kd:ctrl,fn kp:arrow-right ku:ctrl,fn
Hold ctrl key down
Hold fn key down
Press + release arrow-right key
^[[1;5CRelease ctrl key
Release fn key
david@DB-Mac-Studio ~ % ;5C

The fifth line is not shown in your output. Notice that the line includes 1;C, which are the characters typed by cliclick in the last line. Using cliclick to execute option fn right-arrow also fails to use the fn key, producing the action of option right-arrow

Mac Studio M2 Ultra macOS 15.3.1 cliclick 5.1

DavidMBrown avatar Feb 23 '25 15:02 DavidMBrown

I can reproduce the problem, but don’t have a clue why this happens or how to fix it. As fn works in some cases, the problem can neither be the key code nor the system call used. And, the “best” part about it, t (works with fn) and kp (doesn’t work with fn) use the same system calls …

What I found interesting is that AppleScript + System Events seems to be having the same problem.

-- Example 1: press Fn + c
-- This works (like in cliclick)
tell application "System Events"
    key down 63
    keystroke "c"
    key up 63
end tell

-- Example 2: press Fn + F4 (shortcut on my Mac)
-- This does not work (like in cliclick: behavior is as if `fn` wasn’t been pressed)
tell application "System Events"
    key down 63
    key code 118
    key up 63
end tell

BlueM avatar May 28 '25 17:05 BlueM