To make an error free compilation of the sketch of post #3, you need to include the following library file in the sketch, which is not available in the net. I have found one (attached), but I can't include it in the IDE.
Please. This is to emulate a USB keyboard; there are thouasands of applications that can catch keystrokes.
The OP has such an app running. It needs to hear from a keyboard over USB.
TBC: She could take a PC keyboard and plug it in and use it, except… it would be very large and leave over lotsa keys that don't need to be here.
@secretreeve - I can't help you with the digispark problem.
My keyboard emulator, which uses code only similar to what I turned up with google, runs on an old board called a trinket. It has been connected to my iMac and has two buttons and an "app selector", so I can, for example, verify an Arduino sketch by pressing a button.
I believe this is similar to what you are trying to do.
As a first step I tried my device (it's been abandoned) and I find it no longer works! I haven't run this to ground, but the other issue (for me) is that programming the trinket was always just the same kind of PITA as I found the digisparks (of old?) to be…
Other Arduino boards that are much easier to use are almost as cute and small. I sat switch away to one of them. Any USBHID ready board will do, google is your friend.
If I get a chance, I'll find my sketch. I will try to gather what is necessary to figure out why something that always worked doesn't, and suffer through re- flashing the trinket.
My understanding is that board emulates a USB interface with bit-bang software. Not having used it nor a ATtiny85 processor, I can't help with your current problem. But if you can't get it to work, I'll suggest an alternative. Use a board based on the 32u4 processor such as This One. The 32u4 has a native hardware USB interface so it will work with the the Standard Arduino Keyboard Library. It also has a separate hardware UART that you can use at the same time as the USB port for debugging or I/O. This solution won't be quite as compact as what you're trying to do and will require a USB cable between the 32u4 and the laptop. However, I think it will be more powerful and flexible.
What's smaller than a Feather but larger than a Trinket? It's an ItsyBitsy!
will work and is probably not so fussy to use as either digispark or the trinket.
Around my kab, all digisparks and trinkets are permanently deployed after the heroic struggle which was getting a sketch into them that could let them just live out their lives w/o needing to be flashed again…
i decided to go a different route to the digispark and ordered an arduino micro/pro with a 32u4 chip and found a feed about “hid-project”
luckily the remote housing i had already 3d printed is easily modifiable to take the micro/pro.
the new code compiled with respect to that board without any issues. i may well look into developing this further to add a job stick into the top of the remote for axis control during setup of the machine.
as requested, i appreciate you stepping in on this thread alto, you’ve helped me before with previous projects and your assistance is always valueable.
with this code, which was pretty much stolen and adapted from an instructables thread, i’d be unsure how to “hold” a key for extended. im fairly sure it would be changing the “if” so it had an “else” to register the button release.
of course, using delay in code isnt ideal, however for a basic beginning, where the only 2 functions is to send “start” and “stop” commands, its acceptable.
also, my apologies for being the cause of you digging out the trinket lol
1.Take an opportunity to learn button handling which would include debouncing and state change detection. Both are key concepts in this world, and worth knowing about even if only as a challenge because…
2. you could use a button library, ezButton (small e small z Button) for example, which could cut this like butter with a chainsaw.
The key point in either is it would let you do one thing when the button became pressed, and another when the button got released.
Currently, if you read the code, you see the key stroke happens when you press the button, and the key release happens 300 milliseconds later, no matter your fat finger got off the button 200 milliseconds earlier.
If you keep the button down, you will cause another stroke/release pair to be launched, a repeat at ~3 Hz.
When I get to the lab I'll find a gentle ezButton sketch if you haven't by then.
id be highly interested in looking at the ezButton sketch for sure.
so if im understanding your responce right and the code correctly,
the code cycles looking for a button high signal, as soon as its detected then it activates the remainder of the selected buttons code and ignores the second buttons code. the delay only comes into play in order to give you time to release the button and the code go back to scanning for button press signals.
so if im right in that, you could just hold the button and the code will repeatedly cycle that section and just consider it “prolonged button press”
then it sends a command to release all keys, which naturally here includes and consists entirely on the one key that is down:
Keyboard.releaseAll();
It might be clearer had the author sent the correct command to release the single key she knew she had caused to go down, but it is harmless to be general and means less thinking if a time comes for handling combo keystrokes.
The delay is indeed for you to get off the key. Holding it down means when the delay finiches the loop comes around again and you get another key down and key up, which is different to holding a key down.
When you hold down a real key on a real keyboard, usually you get one character, some first longish delay, then the same character sent again at a higher rate, autorepeat.
So in practice it kinda the same, but the subtle and careful (cough!) UI design of a long delay before rapid additional keystrokes is frustrated, and you get 3 characters per second, same time between first to second as from any subsequent Nth and N+1th keystrokes.