【问题标题】:Luamacros for autohotkey用于自动热键的 Lumacros
【发布时间】:2021-02-14 22:10:49
【问题描述】:

我目前正在使用 taran van hemert 的 lua 脚本,它将每个按键保存在文本文件中,autohotkey 将根据该文本文件检测每个按键,我只是想知道如何让 shift 在其他文件上工作键,我的意思是当我按 shift+2 时,它将在文本文件中显示“@”。有人知道怎么做吗?

-- note that some of the code has changed since then (it works better now!)
-- Though, I have since abandoned luamacros, in favor of Interception... which i will abandon in favor of QMK.
-- get luamacros HERE: http://www.hidmacros.eu/forum/viewtopic.php?f=10&t=241#p794
-- plug in your 2nd keyboard, load this script into LUAmacros, and press the triangle PLAY button.
-- Then, press any key on that keyboard to assign logical name ('MACROS') to macro keyboard
clear() --clear the console from last run
local keyboardIdentifier = '0000AAA'


--You need to get the identifier code for the keyboard with name "MACROS"
--This appears about halfway through the SystemID item and looks like 1BB382AF or some other alphanumeric combo.
-- It's usually 7 or 8 characters long.
--Once you have this identifier, replace the value of keyboardIdentifier with it

--Don't ask for keyboard assignment help if the user has manually entered a keyboard identifier
if keyboardIdentifier == '0000AAA' then
    lmc_assign_keyboard('MACROS');
else lmc_device_set_name('MACROS', keyboardIdentifier);
end
--This lists connected keyboards
dev = lmc_get_devices()
for key,value in pairs(dev) do
  print(key..':')
  for key2,value2 in pairs(value) do print('  '..key2..' = '..value2) end
end
print('You need to get the identifier code for the keyboard with name "MACROS"')
print('Then replace the first 0000AAA value in the code with it. This will prevent having to manually identify keyboard every time.')
-- Hide window to tray to keep taskbar tidy
lmc.minimizeToTray = true
--lmc_minimize()

--Start Script
sendToAHK = function (key)
      --print('It was assigned string:    ' .. key)
      local file = io.open("C:\\Users\\Jhon Ryven\\Desktop\\2nd keyboard macros\\keypressed.txt", "w") -- writing this string to a text file on disk is probably NOT the best method. Feel free to program something better!
      --If you didn't put your AutoHotKey scripts into C:/AHK, Make sure to substitute the path that leads to your own "keypressed.txt" file, using the double backslashes.
      --print("we are inside the text file")
      file:write(key)
      file:flush() --"flush" means "save." Lol.
      file:close()
      lmc_send_keys('{F24}')  -- This presses F24. Using the F24 key to trigger AutoHotKey is probably NOT the best method. Feel free to program something better!
end

local config = {
    [45]  = "insert",
    [36]  = "home",
    [33]  = "pageup",
    [46]  = "delete",
    [35]  = "end",
    [34]  = "pagedown",
    [27]  = "escape",
    [112] = "F1",
    [113] = "F2",
    [114] = "F3",
    [115] = "F4",
    [116] = "F5",
    [117] = "F6",
    [118] = "F7",
    [119] = "F8",
    [120] = "F9",
    [121] = "F10",
    [122] = "F11",
    [123] = "F12",
    [8]   = "backspace",
    [220] = "backslash",
    [13]  = "enter",
    [16]  = "rShift",
    [17]  = "rCtrl",
    [38]  = "up",
    [37]  = "left",
    [40]  = "down",
    [39]  = "right",
    [32]  = "space",
    [186] = "semicolon",
    [222] = "singlequote",
    [190] = "period",
    [191] = "slash",
    [188] = "comma",
    [219] = "leftbracket",
    [221] = "rightbracket",
    [189] = "minus",
    [187] = "equals",
    [96]  = "num0",
    [97]  = "num1",
    [98]  = "num2",
    [99]  = "num3",
    [100] = "num4",
    [101] = "num5",
    [102] = "num6",
    [103] = "num7",
    [104] = "num8",
    [105] = "num9",

    [106] = "numMult",
    [107] = "numPlus",
    [108] = "numEnter", --sometimes this is different, check your keyboard
    [109] = "numMinus",
    [110] = "numDelete",
    [111] = "numDiv",
    [144] = "numLock", --probably it is best to avoid this key. I keep numlock ON, or it has unexpected effects

    [192] = "Sc029",  --this is the tilde key just before the number row
    [9]   = "tab",
    [20]  = "capslock",
    [18]  = "alt",
    [91]  = "winkey",

    [string.byte('Q')] = "q",
    [string.byte('W')] = "w",
    [string.byte('E')] = "e",
    [string.byte('R')] = "r",
    [string.byte('T')] = "t",
    [string.byte('Y')] = "y",
    [string.byte('U')] = "u",
    [string.byte('I')] = "i",
    [string.byte('O')] = "o",
    [string.byte('P')] = "p",
    [string.byte('A')] = "a",
    [string.byte('S')] = "s",
    [string.byte('D')] = "d",
    [string.byte('F')] = "f",
    [string.byte('G')] = "g",
    [string.byte('H')] = "h",
    [string.byte('J')] = "j",
    [string.byte('K')] = "k",
    [string.byte('L')] = "l",
    [string.byte('Z')] = "z",
    [string.byte('X')] = "x",
    [string.byte('C')] = "c",
    [string.byte('V')] = "v",
    [string.byte('B')] = "b",
    [string.byte('N')] = "n",
    [string.byte('M')] = "m",

    [string.byte('0')] = "0",
    [string.byte('1')] = "1",
    [string.byte('2')] = "2",
    [string.byte('3')] = "3",
    [string.byte('4')] = "4",
    [string.byte('5')] = "5",
    [string.byte('6')] = "6",
    [string.byte('7')] = "7",
    [string.byte('8')] = "8",
    [string.byte('9')] = "9",
    [255+44] = "printscreen",
        [145] = "scrolllock",

}

-- define callback for whole device
lmc_set_handler('MACROS', function(button, direction)
    --Ignoring upstrokes ensures keystrokes are not registered twice, but activates faster than ignoring downstrokes. It also allows press and hold behaviour
        if (direction == 0) then return end -- ignore key upstrokes.
    if type(config[button]) == "string" then
                print(' ')
                print('Your key ID number is:   ' .. button)
                print('It was assigned string:    ' .. config[button])
                sendToAHK(config[button])
    else
                print(' ')
                print('Not yet assigned: ' .. button)
    end
end) ```

【问题讨论】:

    标签: lua autohotkey


    【解决方案1】:

    根据我在网上找到的信息,应该有第四个参数flags,它可以为您提供有关修饰键的信息。

    log_handler = function(button, direction, ts, flags)
      print('Callback for device: button ' .. button .. ', direction '..direction..', ts '..ts..', flags '..flags)
    end
    

    或者,如果按下 shift,您会记得。你处理它的向下冲程,所以你知道它被按下了吗?

    编辑:

    像这样修改代码,以访问 flags 参数。

    如需更多信息,请参阅 Lua 用户手册。你不能修改你不理解的东西。对不起。

    lmc_set_handler('MACROS', function(button, direction, ts, flags)
    
        print(flags)
        --Ignoring upstrokes ensures keystrokes are not registered twice, but activates faster than ignoring downstrokes. It also allows press and hold behaviour
        if (direction == 0) then return end -- ignore key upstrokes.
        if type(config[button]) == "string" then
                    print(' ')
                    print('Your key ID number is:   ' .. button)
                    print('It was assigned string:    ' .. config[button])
                    sendToAHK(config[button])
        else
                    print(' ')
                    print('Not yet assigned: ' .. button)
        end
    end)
    

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 2013-03-20
      • 2014-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多