V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  Tink  ›  全部回复第 81 页 / 共 1162 页
回复总数  23232
1 ... 77  78  79  80  81  82  83  84  85  86 ... 1162  
2025 年 4 月 27 日
回复了 Angryraven 创建的主题 macOS 抄一下各位 MX Master3S 的键位设置,鞠躬 🙇‍♂️
我是 hammerspoon 实现的

```
-- 创建日志记录器
local logger = hs.logger.new('MouseShortcuts','debug')

-- 创建鼠标事件监听器
-- Logitech Anywhere 2S 按键映射
local mouseButtons = {
left = 0,
right = 1,
back = 3, -- 靠后侧键
forward = 4, -- 靠前侧键
wheel_button = 2 -- 滚轮后边的功能键
}

-- 声明监听器变量
local mouseWatcher = nil
local scrollWatcher = nil

-- 定义快捷键行为
local function handleMouseButton(button, modifiers)
-- 滚轮后边的功能键 = Mission Control
if button == mouseButtons.wheel_button then
hs.task.new("/usr/bin/open", nil, {"-a", "Mission Control"}):start()
return true
end

-- 靠前侧键 = 返回
if button == mouseButtons.forward then
hs.eventtap.keyStroke({"cmd"}, "[")
return true
end

-- 靠后侧键 = 前进
if button == mouseButtons.back then
hs.eventtap.keyStroke({"cmd"}, "]")
return true
end

return false
end

-- 处理滚轮横向滚动
local function handleScrollWheel(event)
-- 使用 axis2 来监听横向滚动
local dx = event:getProperty(hs.eventtap.event.properties['scrollWheelEventDeltaAxis2'])

-- 输出滚轮事件日志
if dx ~= 0 then
logger.i(string.format("滚轮横向拨动 - 方向值: %d", dx))
end

-- 如果不是横向滚动,直接返回
if dx == 0 then return false end

-- 直接根据方向触发切换
if dx < 0 then
logger.i("切换到左边桌面")
hs.task.new("/usr/bin/osascript", nil, {"-e", 'tell application "System Events" to key code 123 using control down'}):start()
return true
elseif dx > 0 then
logger.i("切换到右边桌面")
hs.task.new("/usr/bin/osascript", nil, {"-e", 'tell application "System Events" to key code 124 using control down'}):start()
return true
end

return false
end

-- 创建监听器的函数
local function createWatchers()
-- 创建鼠标按键事件监听
mouseWatcher = hs.eventtap.new({
hs.eventtap.event.types.otherMouseDown,
hs.eventtap.event.types.otherMouseUp,
hs.eventtap.event.types.leftMouseDown,
hs.eventtap.event.types.leftMouseUp,
hs.eventtap.event.types.rightMouseDown,
hs.eventtap.event.types.rightMouseUp,
hs.eventtap.event.types.otherMouseDragged
}, function(event)
local eventType = event:getType()
local button = event:getProperty(hs.eventtap.event.properties.mouseEventButtonNumber)
local modifiers = event:getFlags()

-- 转换修饰键为数组形式
local modArray = {}
for k, v in pairs(modifiers) do
table.insert(modArray, k)
end

-- 获取事件类型的可读名称
local eventNames = {
[hs.eventtap.event.types.otherMouseDown] = "其他按键按下",
[hs.eventtap.event.types.otherMouseUp] = "其他按键释放",
[hs.eventtap.event.types.leftMouseDown] = "左键按下",
[hs.eventtap.event.types.leftMouseUp] = "左键释放",
[hs.eventtap.event.types.rightMouseDown] = "右键按下",
[hs.eventtap.event.types.rightMouseUp] = "右键释放",
[hs.eventtap.event.types.otherMouseDragged] = "其他按键拖动"
}

-- 输出鼠标事件日志
-- logger.i(string.format("鼠标事件 - 类型: %s, 按钮: %d, 修饰键: %s",
-- eventNames[eventType] or eventType,
-- button or 0,
-- hs.inspect(modArray)))

-- 仅对按下事件执行操作
if eventType == hs.eventtap.event.types.otherMouseDown then
return handleMouseButton(button, modArray)
end

return false
end)

-- 创建滚轮事件监听
scrollWatcher = hs.eventtap.new({
hs.eventtap.event.types.scrollWheel
}, handleScrollWheel)

-- 启动监听器
mouseWatcher:start()
scrollWatcher:start()
end

-- 检查并重启监听器的函数
local function checkWatchers()
if not mouseWatcher:isEnabled() or not scrollWatcher:isEnabled() then
logger.w("监听器已停止,尝试重新启动...")
-- 停止现有监听器
if mouseWatcher then mouseWatcher:stop() end
if scrollWatcher then scrollWatcher:stop() end
-- 重新创建并启动监听器
createWatchers()
logger.i("监听器已重新启动")
end
end

-- 创建定时器定期检查监听器状态
local watcherChecker = hs.timer.new(5, checkWatchers)
watcherChecker:start()

-- 初始化监听器
createWatchers()

-- 添加快捷键用于手动重启监听器
hs.hotkey.bind({"cmd", "alt"}, "m", function()
logger.i("手动重启鼠标监听器...")
createWatchers()
logger.i("鼠标监听器已重启")
end)

logger.i("鼠标快捷键模块已加载")
```
只要是浏览过的网站都自动保存全文

意思是谷歌搜索之类的也保存吗
@SakuraYuki #19 确实下架了
2025 年 4 月 27 日
回复了 kuawo 创建的主题 问与答 大佬们问个安卓手机选择问题,给加拿大亲人用
国外用的话 pixel 或者三星呗
2025 年 4 月 27 日
回复了 omz 创建的主题 旅行 有哪些地方,是你去过一次还想再去的?
清迈算吗
2025 年 4 月 27 日
回复了 BeFun 创建的主题 职场话题 “上 4 休 3”,但是要在工资要减少到原有工资的 80%
@BeFun #15 这也太爽了吧,啥单位
直接用 IP 可以不?
类似于目录程序的都能满足要求
需求没听懂呀
2025 年 4 月 26 日
回复了 hailongchang 创建的主题 问与答 版上有人申请成功过 telegram 的 app_id 和 hash_id 吗?
前天申请的
2025 年 4 月 26 日
回复了 hailongchang 创建的主题 问与答 版上有人申请成功过 telegram 的 app_id 和 hash_id 吗?
多点几次就有了
2025 年 4 月 25 日
回复了 PendingOni 创建的主题 生活 [记录]-2025-04-25 地铁站务工作
白夜休休

哪个城市啊
2025 年 4 月 24 日
回复了 MicroG 创建的主题 汽车 25 岁第一辆车,想买一辆两门二手油车,求建议
这价格无脑 brz
2025 年 4 月 24 日
回复了 MicroG 创建的主题 汽车 25 岁第一辆车,想买一辆两门二手油车,求建议
brz
2025 年 4 月 24 日
回复了 nathanw 创建的主题 问与答 2025 年了,你们都用哪款外接键盘?
K3/84
2025 年 4 月 23 日
回复了 YangZenxi 创建的主题 问与答 国行 TCL 电视真的没有办法接入 HomeKit 吗?
ha 不是有 hk 桥吗,tcl 接入 ha ,然后通过桥反向接入 hk 行不行
2025 年 4 月 22 日
回复了 adaashili 创建的主题 Surge Surge Ponte 功能请教
tailscale
2025 年 4 月 21 日
回复了 jamel 创建的主题 问与答 想给 老婆,亲妈,岳母 分别 买个 玉手镯
1k 的话买个银饰,不要买玉
1 ... 77  78  79  80  81  82  83  84  85  86 ... 1162  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2908 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 131ms · UTC 04:02 · PVG 12:02 · LAX 21:02 · JFK 00:02
♥ Do have faith in what you're doing.