keyboard-shortcuts - 使用 Karabiner-Elements 将应用程序键映射到插入符位置的右键单击

标签 keyboard-shortcuts mouse key-bindings caret karabiner

要使用 Karabiner-Elements 将应用程序键映射到右键单击,可以使用:

"simple_modifications": [
    {
        "from": {
            "key_code": "application"
        },
        "to": {
            "pointing_button": "button2"
        }
    },

但是,这将在鼠标指针的位置执行右键单击。我希望它将指针移动到插入符号的位置,然后执行右键单击。
据推测,要做到这一点,我需要使用 "complex_modifications" rule
我的主要问题是我不知道如何将鼠标指针位置更改为插入符号位置。 使用 AutoHotkey,这里有一个答案 Moving the mouse pointer to the cursor
我不能说我真的理解那里的答案,但无论如何我都希望用 Karabiner-Elements 做到这一点

最佳答案

我认为您可以在较新的 13+ 版本的 Karabiner-Elements 中将鼠标光标移动到指定位置(我无法在 MacOS High Sierra 中使用它)。
不过,我担心首先很难获得选择的 x 和 y 值。

但是:
您可以使用 AppleScript UI 属性"AXFocusedUIElement" 右键单击​​选定的 UI 元素。
(例如,这确实适用于 Finder 窗口文件和文件夹以及 TextEdit 选择,但遗憾的是不适用于 Finder 桌面上的 Safari 选择和文件。)
如果您的主要目标是在 Finder 的窗口内导航,则此脚本* 可以完美运行。

{  "description": "Right-click via Karabiner-Elements/shell-command/AppleScript",
   "manipulators": [ {
            "type": "basic",
            "from": {
                "key_code": "left_arrow",
                "modifiers": {"mandatory": "left_control" }
                    },
              "to": [  {
 "shell_command": "osascript -e 'tell application \"System Events\" to set _/¯
  activeApp to name of first process whose frontmost is true \n tell application _/¯
  \"System Events\" to tell application process activeApp \n set mySelect _/¯
  to value of attribute \"AXFocusedUIElement\" \n tell mySelect to perform _/¯
  action \"AXShowMenu\" \n end tell'"
}  ]  }  ]
}

请注意,整个 osascript(“osascript -e ' … >> … end tell'”)需要一行(为了更好的可读性,我插入了“_/¯”)。

(* AppleScript 的“tell application … end tell”部分在网上有多种变体。
并且:当然,您可以将我的 Ctrl-LeftArrow 快捷键更改为您喜欢的任何一个。)

关于keyboard-shortcuts - 使用 Karabiner-Elements 将应用程序键映射到插入符位置的右键单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63395636/

相关文章:

c++ - Windows - SDL_PumpEvents 重置为系统光标

actionscript-3 - Flash CS4 AS3 水平影片剪辑随鼠标移动滚动

java - 添加 keyListener 来模拟鼠标单击链接,页面是使用 Javax jspx servlet 制作的。 getElementById 返回 null

key-bindings - 如何设置自定义键绑定(bind)以在 Atom 编辑器中运行脚本或执行命令?

build - 自定义构建键绑定(bind) Sublime Text

visual-studio-2010 - 在 Visual Studio 2010 中将 Ctrl+S 重新映射到 File.Save

visual-studio - 如何在 Visual Studio 中突出显示文本中出现的搜索词?

visual-studio-code - Visual Studio Code 是否具有框选/多行编辑功能?

c++ - 模拟按下的快捷方式

java - Action 和 ActionMap - 向我解释这种行为