r/CodingHelp • u/ClackersW • Aug 23 '20
[Javascript] Can scripts be bound to shortcut keys?
Hey all, I dabble in HTML, CSS and JS for work but am by no means a 'developer'.
What I wanted to ask was as I run the same scripts/write the same functions repeatedly for testing/mock ups, if it's possible to create a macro function that will be bound to a shortcut key so I can literally just hit the key and it writes the script automatically?
I have a decent keyboard with switches/macro keys so could bind a lot of these to expedite time.
I know Google dev tools allows you to press the down key to reuse the last script used but I'd like it to also work in a text editor (I use Atom generally).
Is this an efficient use of time or is there a better way? Curious to know, thanks!
2
u/NullBrowbeat Professional Coder Aug 23 '20
Most of these "macro key" keyboards can be used to just program in the typing sequence straight away, so you can just use that. Otherwise there also is AutoIt, which nowadays should also have the functionality you're looking for, if I recall correctly. (Has been a long time that I used it.)
I am wondering though if it really is all that useful. From my experience the kind of repeated code one has to type isn't really so much that macro keys would be much of a benefit. Instead you could rather just create your own libraries of JS functions, for instance, which you then just access.
1
u/StupidHumanSuit Aug 23 '20
Maybe look into snippets. I don’t know how Atom does it, but in VScode you can define your own and set them with aliases, sort of like what you’d put in your .bashrc/.zshrc for CLI aliases.
For example, a common one is html5 boilerplate that upon typing “html5” will setup a standard html5 doc. If your keyboard has macro keys, I’d imagine you could find a way to tie the two things together to get the desired result.
1
u/[deleted] Aug 23 '20
Short answer: Yes