Analog keyboard emulator

I've an Arduino micro, and I want to send a command to my pc of a key pressed by a %. To make the character of a generic game move at a % of his total speed (i want it to work with every key, like 'K' for example), how can I do it?

EXAMPLE:
Send the key 'A' with a 50% intensity
Send the key 'C' with a 25% intensity

Welcome to the forum

What sort of key do you have that you can press by a certain percentage ? Has it got an analogue output or is it a keyboard key ?

for now I wanted to use a analogRead of a potentiometer for every key, with a range of values mapped at 0-100%

Using potentiometers will certainly give you analogue signals but I can't imagine how you think this would work in practice. Please describe your vision in more detail

if there is a reading of 50% of the 'A' potentiometer, the character will move left at 50% speed

So each key will move a pot and depending on how far the pot has moved the Arduino will send a different keystroke

Is that what you are suggesting ?
If so, then how many keys will there be ?

No, that's not what I'm suggesting. I'm trying to say that a single potentiometer is related to a single key on the keyboard, but it can send the command (for example 'a') with different intensities.
If the potentiometer gives a reading value of 10% the 'a' command will be sent at 10% intensity, resulting in the character of a generic game moving at 10% speed at left, but if the reading increases at 70% (for example) the character will then move at 70% speed, etc...

Please specify the encoding of such a command. The Serial port only can send characters, so the percentage has to be encoded somehow. It's up to you to find out how the pot value is converted into text and appended to the command.

I'm using a arduino Micro that can also send commands to the pc, but I don't know how to do what i need, I can't write you an encode

Which part don't you know ?

Can you read a pot using analogRead() ?
Can you test the value returned by analogRead() ?
Can you send a keystroke to the PC ?

the last one

Take a look at https://docs.arduino.cc/tutorials/micro/keyboard-press

are you looking for something like this?

const byte ButPin = A1;
const byte PotPin = A1;

byte butState;

void
loop (void)
{
byte but = digitalRead (ButPin);
if (butState != but) {
butState = but;
delay (20); // debounce

    if (LOW == but)  {
        int anlg = analogRead (PotPin) * 100 / 1024;

        char c;
        if (25 > anlg)
            c = 'A';
        else if (50 > anlg)
            c = 'B';
        else if (75 > anlg)
            c = 'C';
        else
            c = 'D';
        Serial.print (c);
    }
}

}

void
setup (void)
{
Serial.begin (9600);

pinMode (ButPin, INPUT_PULLUP);
butState = digitalRead (ButPin);

}

This shows in detail how to send keystrokes to the pc

So you will send a character code for "A", then a number?

how are you reading the input? what is the input?

Baffling.

So you will send a character code for "A", then a number?

Is one way to interpret your words. There is no such thing as sending a more or less intense character, like how hard you mash the key down or something.

Are you perhaps looking to send a character repeatedly, at a rate determined by a corresponding potentiometer?

a7

i tried to implement a PWM way to send the 'a' command to my pc, but it isn't working (i've tried different duty cicles lenghts but none of them worked)

why would you think that would work?

what triggers sending the information (format??)

can you confirm if the above is accurate?

i used the Keyboard library with a function that (for example when the reading of the potentiometer is at 50%) it execute the function Keyboard.press('a') for 50 micros, and then the function Keyboard.release('a') for the remaining 50 micros (for a cycle duration of 100 micros).

As I already told, I don't know how to send and make the computer understend the format of the command sent, so I can't confirm it

How does this happen if you are just sending 'A's with whatever means you have, like by keyboard, no programming involved?

You speak of a generic game, please instead tell us about a real game, one that receives characters to make something go, and how that works.

Without knowing how the "generic game" interprets keystrokes, there's no way to help you.

Could it be… it moves as long as you hold the key down? Is that because the key went down, and never up, or because the keyboard is auto-repeating the character.

Or does it move with each 'A', and sending them periodically at an adjustable rate is what you think might work?

Or?

a7