V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  Tink  ›  全部回复第 33 页 / 共 1115 页
回复总数  22292
1 ... 29  30  31  32  33  34  35  36  37  38 ... 1115  
@saltpi 我也申请一下
退货
是哪个投到哪个?
安卓到 mac 的话就是 scrcpy

mac 到安卓的话就要上采集卡
@john2023 #15 实时的话你已经有 bot 了,写个插件监听公众号文章消息就可以了
141 天前
回复了 maxmax4max 创建的主题 职场话题 谁对谁错?
小孩才讲对错
141 天前
回复了 sentinelK 创建的主题 反馈 最近被管理员移动帖子不太正常
可能是误操作
需要一个微信 bot ,然后将需要转发的公众号文章订阅为 rss ,每分钟刷一次,检测到新文章之后给到 bot ,然后 bot 推到群里
141 天前
回复了 rust 创建的主题 全球工单系统 今日笑点以及避雷
他这个不内置风扇?
能活着就阿弥陀佛了
需要邀请码吧
142 天前
回复了 Kudos 创建的主题 生活 宝宝脸被抓,我该怎么做
小朋友的事情让小朋友解决
143 天前
回复了 kidult 创建的主题 MacBook 大家的 mac 合盖插电时会有温度吗?
会吗?我的盒盖之后基本是冰的
都 404 了
可以的
144 天前
回复了 NicholasNC 创建的主题 电动汽车 裸车预算 10w 以内,求纯电车推荐
小鹏?
144 天前
回复了 stevexiaojobs 创建的主题 Apple [email protected] 是苹果官方的邮箱吗?
我还以为这个帖子是硬🎣呢
144 天前
回复了 tt83 创建的主题 旅行 有哪些地方,是你去过一次不想再去的?
fuping
我是 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("鼠标快捷键模块已加载")
```
1 ... 29  30  31  32  33  34  35  36  37  38 ... 1115  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3122 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 83ms · UTC 11:41 · PVG 19:41 · LAX 04:41 · JFK 07:41
Developed with CodeLauncher
♥ Do have faith in what you're doing.