Need Help Finishing a Macros Keyboard for Math
Posted: 25 Jan 2018, 08:34
So I've always found it super annoying that the default keyboard has never been optimized well for typing out math equations for anything past pre-algebra. In order to use parentheses or exponents you always have to first hit shift. Same with adding anything together, because + is the second function of the = key. So when I hit college, I got a cheap numeric keyboard and spent a weeknight plugging in macros for HIDmacros. Then it just stopped working. Maybe it was a computer update. I don't know, and don't particularly care. Now I've been browsing forum threads learning how to use Lua, and rebuilding my macros. Everything has been working almost great. There's just a few keys left that I gotta nail down, and everything will be good. This is my script so far:
Running down the list, everything seems pretty normal. A lot of sines, cosines, logarithms, and stuff. It's at the line for the buttons 109 onward that I need help with. The first key is supposed to be a carrot for exponents. The next one is for typing out square roots. Then the final two are for opened and closed parentheses, respectively. If anybody has any idea of how I can make those keys work, it would be great. Preferably even without the closed bracket ( } ), but if that's not doable, I understand. I'm a real noob at coding. 
Code: Select all
-- assign logical name to my external keyboard
lmc_device_set_name('MathCros', '2F1C1E94');
-- define callback for whole device
lmc_set_handler('MathCros',function(button, direction)
if (direction == 1) then return end -- ignore down
if (button == 97) then lmc_send_keys('sec(')
elseif (button == 98) then lmc_send_keys('csc(')
elseif (button == 99) then lmc_send_keys('cot(')
elseif (button == 100) then lmc_send_keys('sin(')
elseif (button == 101) then lmc_send_keys('cos(')
elseif (button == 102) then lmc_send_keys('tan(')
elseif (button == 103) then lmc_send_keys('log(')
elseif (button == 104) then lmc_send_keys('ln(')
elseif (button == 105) then lmc_send_keys('pi')
elseif (button == 13) then lmc_send_keys('/')
elseif (button == 109) then lmc_send_keys('^{ }')
elseif (button == 107) then lmc_send_keys('\sqrt{ }')
elseif (button == 111) then lmc_send_keys('(')
elseif (button == 106) then lmc_send_keys(')')
else print('Not yet assigned: ' .. button)
end
end)
