Activating keyboard button with a mosfet and arduino

Hello

I would like to activate the space bar with an arduino, meaning i want it to work as if i was pressing the space bar, but instead of pressing the key on the keyboard, i activate it from arduino.

I was thinking of using a mosfet to simply short the circuit and use the arduino to control the mosfet, would this work?

I know the Leonardo can emulate a keyboard, but i can't use the leonardo, i need the signal to come from the keyboard

thanks

No, don't go for that. Use an opto coupler instead.
There would be difficulties handling GND.

1 Like

Easier is the use of an optocoupler for shorting buttons.

Why? Most OS aggregate all keyboard input (supports multiple keyboards, same key on multiple keyboards will have the same effect). In that case, a space bar key press coming from the physical keyboard will be identical to a virtual space bar key press coming from an HID like the Leo.

Hi
I read somewhere that it is possible to know from which keyboard a key was pressed

Ok, however does your application actually do that? Also things that you "read somewhere" are often false.

will the PC817C work?

Any simple optocoupler will work for this project.

this is where i read it from:
windows - Is it possible to determine which keyboard sent a keypress? - Stack Overflow

It may be possible - but that doesn't mean that it is done. Most apps try to use any and all keyboards that are attached. Doesn't it make sense to do so? If you wrote the app, you can control that, too.

This is an example of not being able to really help because of not knowing at all what you are using it for.

The RawInput DLL implements the keyboard hook which affects all running programs until you terminate your program.

hi thanks for reply but i can't follow exactly what you mean

Get the code from the link and study it. Try to run the example and find out whether the old WinXP code still works today.

i'm essentially trying to use it in a game and i don't want to get caught.

Then use an optoisolator. Do some research on that and come back if there are any questions...

Hi
I did some research, (here explains pretty well how a keyboard works How do Computer Keyboards Work? :thinking::keyboard::keyboard::hammer_and_wrench: - YouTube)
I saw some schematics and i think i was able to get the polarities right but i'm not sure if i need to add any resistors? because many of the schematics i saw had resistors
Would this work?

The LED of the optocoupler deserves a current limiting resistor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.