Skip to content

Instantly share code, notes, and snippets.

@caiwan
Created May 8, 2018 23:11
Show Gist options
  • Save caiwan/9374045751d14717c2b072b4e0fcdd14 to your computer and use it in GitHub Desktop.
Save caiwan/9374045751d14717c2b072b4e0fcdd14 to your computer and use it in GitHub Desktop.
External key macros for Photoshop for a numeric keypad
clear()
local keyboardIdentifier = '16BFD3AF'
lmc_print_devices()
-- assign logical name to macro keyboard
if keyboardIdentifier == '0000AAA' then
lmc_assign_keyboard('MACROS');
else lmc_device_set_name('MACROS', keyboardIdentifier);
end
--
boop = function(button, direction)
if direction == 1 then print('beep')
else print('boop' .. button)
end
end
-- photoshop function keystroke definitions
increase_brush = function() lmc_send_keys('[') end
decrease_brush = function() lmc_send_keys(']') end
zoom_in = function() lmc_send_keys('^{NUMPLUS}') end
zoom_out = function() lmc_send_keys('^{NUMMINUS}') end
zoom_reset = function() lmc_send_keys('^0') end
history_step_back = function() lmc_send_keys('^%z') end
local is_brush_selected = true
toggle_brush = function()
if (is_brush_selected) then lmc_send_keys('b')
else lmc_send_keys('e') end
is_brush_selected = not is_brush_selected
end
backspace = function() lmc_send_keys('{BACKSPACE}') end
lasso_tool = function() lmc_send_keys('l') end
deselect = function() lmc_send_keys('^d') end
marquee_tool = function() lmc_send_keys('m') end
move_tool = function() lmc_send_keys('v') end
local is_transform_selected = false
transformation_tool = function()
if (is_transform_selected) then
lmc_send_keys('~')
else
lmc_send_keys('^t')
end
is_transform_selected = not is_transform_selected
end
swap_colors = function() lmc_send_keys('x') end
flip_canvas = function() lmc_send_keys('+{F2}') end
new_layer = function() lmc_send_keys('^+n~') end
merge_layer_down = function() lmc_send_keys('^e') end
copy = function() lmc_send_keys('^c') end
paste = function() lmc_send_keys('^v') end
cut = function() lmc_send_keys('^x') end
magic_wand = function() lmc_send_keys('w') end
gradient_fill = function() lmc_send_keys('g') end
-- numeric keypad function map
key_function_map = {}
key_function_map[111] = increase_brush -- /
key_function_map[106] = decrease_brush -- *
key_function_map[8] = history_step_back -- backspace
key_function_map[109] = zoom_out -- -
key_function_map[107] = zoom_in -- +
key_function_map[13] = zoom_reset -- enter
-- num lock on
key_function_map[103] = lasso_tool -- 7
key_function_map[104] = move_tool -- 8
key_function_map[105] = toggle_brush -- 9
key_function_map[100] = new_layer -- 4
key_function_map[101] = deselect -- 5
key_function_map[102] = merge_layer_down -- 6
key_function_map[97] = swap_colors -- 1
key_function_map[98] = marquee_tool -- 2
key_function_map[99] = transformation_tool -- 3
key_function_map[96] = flip_canvas -- 0
key_function_map[110] = backspace -- .
-- num lock off
key_function_map[36] = boop -- 7/home
key_function_map[38] = boop -- 8/up
key_function_map[33] = boop -- 9/pgup
key_function_map[37] = gradient_fill -- 4/left
key_function_map[12] = magic_wand -- 5
key_function_map[39] = boop -- 6/right
key_function_map[35] = copy -- 1/end
key_function_map[40] = paste -- 2/down
key_function_map[34] = cut -- 3/pgdown
key_function_map[45] = boop -- 0/insert
key_function_map[46] = backspace -- ./del
-- define callback for whole device
lmc_set_handler('MACROS',function(button, direction)
if (direction == 1) then return end -- ignore down ATM
if (key_function_map[button] ~= nil) then key_function_map[button](button, direction)
else print('Not assigned:' .. button)
end
end)
--This lists connected keyboards
function getdevices()
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
end
getdevices()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment