是否可以找到解决方法?
我知道 M 和 N 不是 G 键,但我希望根据最后的按键输入有两个不同的按键序列
说实话,我不知道从哪里开始。
-- Variable to track the last key pressed
local lastKeyPressed = nil
function OnEvent(event, arg)
if event == "G_PRESSED" then
if arg == 77 then -- Direct key code for "M"
lastKeyPressed = "m"
elseif arg == 78 then -- Direct key code for "N"
lastKeyPressed = "n"
end
end
-- Check if the scroll wheel button is pressed to activate the macro
if event == "MOUSE_BUTTON_PRESSED" and arg == 3 then -- Assuming middle mouse button (scroll wheel) is used
QP()
end
end
function QP()
local leanDuration = 25 -- Duration to hold lean in milliseconds
local pauseDuration = 40 -- Pause between actions in milliseconds
if lastKeyPressed == "n" then
-- If N was the last key, press M then N
PressKey("m")
Sleep(leanDuration)
ReleaseKey("m")
Sleep(pauseDuration)
PressKey("n")
Sleep(leanDuration)
ReleaseKey("n")
elseif lastKeyPressed == "m" then
-- If M was the last key, press N then M
PressKey("n")
Sleep(leanDuration)
ReleaseKey("n")
Sleep(pauseDuration)
PressKey("m")
Sleep(leanDuration)
ReleaseKey("m")
else
-- Default action if no key has been pressed yet (optional)
PressKey("n")
Sleep(leanDuration)
ReleaseKey("n")
Sleep(pauseDuration)
PressKey("m")
Sleep(leanDuration)
ReleaseKey("m")
end
lastKeyPressed = nil
end
根据文档,应该可以获取键盘输入,但我无法让它们工作 - 也许是因为我的键盘不是来自罗技的。无论哪种方式,为了回答你的问题,我都会使用修饰符,例如
Alt
、Shift
或 Ctrl
。这是一个例子:
-- Variables
local leanDuration = 25
local pauseDuration = 40
local function Press(key1, key2)
PressKey(key1)
Sleep(leanDuration)
ReleaseKey(key1)
Sleep(pauseDuration)
PressKey(key2)
Sleep(leanDuration)
ReleaseKey(key2)
end
function OnEvent(event, arg)
-- Abort if not MMB pressed
if event ~= "MOUSE_BUTTON_PRESSED" or arg ~= 3 then return end
-- Get button modifier
-- local lalt = IsModifierPressed("lalt") -- Left Alt
-- local ralt = IsModifierPressed("ralt") -- Right Alt
-- local alt = IsModifierPressed("alt") -- Either Alt
-- local lshift = IsModifierPressed("lshift") -- Left Shift
-- local rshift = IsModifierPressed("rshift") -- Right Shift
-- local shift = IsModifierPressed("shift") -- Either Shift
-- local lctrl = IsModifierPressed("lctrl") -- Left CTRL
-- local rctrl = IsModifierPressed("rctrl") -- Right CTRL
local ctrl = IsModifierPressed("ctrl") -- Either CTRL
-- Alternatively, use lock keys
-- local scrolllock = IsKeyLockOn("scrolllock")
-- local capslock = IsKeyLockOn("capslock")
-- local numlock = IsKeyLockOn("numlock")
-- Control is pressed
if ctrl then
Press("m", "n")
else
Press("n", "m")
end
end
如果这不能完全帮助您,那么最好的选择是使用AutoHotkey之类的东西。