简体   繁体   中英

What C++ type do keycodes from HID Project Use?

Recently I have found myself incredibly frustrated in programming my recently built 9 key macro keyboard I made using an arduino pro micro. The keyboard is fully functional hardware wise, but I am very new to C++ and cannot get it to do exactly what I want. Essentially, I wish to bind the 9 keys to the F13-F21 keys using an array associated with the key values, 0 through 8. To do so, I wish to use an array, but because I do not know what type the key values from HID project are, I cannot get the array to pass any meaningful data to the Keyboard.press function.

static const uint8_t KEYBINDS[] = {KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20, KEY_F21};

A scenario similar to what I'm trying to do is the following, where I use a Values array to pass data to the Keyboard.press() function, just using numbers.

static const uint8_t Values[] = {1, 4, 3, 6, 8};

Keyboard.press(Values[2]);

However, the Keyboard.press() function requires data that looks like this,

KEY_F13
KEY_TAB
KEY_SPACEBAR

I don't know what type of data this is. It doesn't work as string, uint8_t or uint16_t, or anything else I've tried. I can't use no type, and void doesn't work for arrays, so I have no idea what else to try. The type is not specified in the source code, at least not to what I can see, but I don't really know how to look.

Some infos; using Keyboard.press(KEY_F13); does EXACTLY what I want it to. I just don't know how to pass that through an array to the function. Technically, I could get this to work using a horrible if-statement nest with a bunch of Keyboard.press() commands, but I would much rather figure this out the right way.

Please let me know if any additional info is needed to help answer this question.

HID-Project Documentation

https://github.com/NicoHood/HID/wiki

Those are values of enum type KeyboardKeycode from ImprovedKeylayouts.h. While enum's named value can be casted implicitly to an integral type, opposite requires explicit cast.

Not sure what problem you had to diagnose it, compiler diagnostics should have point at the mismatch. After all you also could used a type-agnostic declaration using C++11

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM