How do i use a variable to press a key with robot class

Basically I’m trying to make a function that will type the key i need

Because its a function i give it a string with a variable which is the key i need to press and the robot variable how do i do it?

I’m sorry but I don’t understand what is it you try to do.

Yea i dont really do too so
I need a function to press the button i need which will do something like this

void SendKey(String KeyINeed, Robot robot) {

so pressing a key and releasing it

Still not sure I get what you want but I guess you are looking for the keyPressed() function.

i dont know how to explain it but
i have a function that should press a key that’s specified when it gets called
so the caller looks like this:

Presskey(robot, S)

and the PressKey function should press and release the second variable S in this example

do you use
import java.awt.Robot; ?
where do you want to press a key? in an another app?

Yes i am using it.

I want to emulate a keyboard press to make it work in another app

here is an example:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent; 

Robot robot;
String  keyString="hello world";
void setup() {

  size(100, 100);
  try { 
    robot = new Robot(); 
  catch (AWTException ex) {

void draw() {
  sendKeys(robot, keyString);

void sendKeys(Robot robot, String keys) {
  for (char c : keys.toCharArray()) {
    int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
    if (KeyEvent.CHAR_UNDEFINED == keyCode) {
      throw new RuntimeException(
        "Key code not found for character '" + c + "'");

run the sketch then go back to processing ide