holding button down code

well hello there,

i want to run a code on my arduino nano with to buttons which activates a relay one button is going to be pushed in and then send a signal to the raly that it must ''run'' for 10 seconds but the 2nd button i want to press it and hold it and then send a signal that the relay will run during the time that the button is held down. i dont relay how the code for the 2nd buttons must be writen can you guys help me out
this is the code i have so far

int ButtonA = 5; //shot
int ButtonB = 4; //manual override
int Relay = 11; //relay module
int "time" = 10000 
void setup() {
 pinMode(ButtonA, INPUT);
 pinMode(ButtonB, INPUT);
 pinMode(Relay, OUTPUT);
}



void loop() {{
  if(digitalRead(ButtonA) == LOW)
  { digitalWrite(Relay, LOW);
    delay("time");
    digitalWrite(Relay, HIGH);
    }
  if(digitalRead(ButtonB) == LOW);
  { digitalWrite(Relay, LOW);
    
}{
 delay(100);
}}

Read up on state-change and millis() timing.

i have a new code new maybe you guys can check if it is any good

int ButtonA = 5; //shot
int ButtonB = 4; //manual override
int Relay = 11; //relais module
float pressLength_milliSeconds = 0;
int optionTwo_milliSeconds = 2000; 




void setup() {
 pinMode(ButtonA, INPUT_PULLUP);
 pinMode(ButtonB, INPUT_PULLUP);
 pinMode(Relay, OUTPUT);
 Serial.begin(9600);
}



void loop() {{
 while(digitalRead(ButtonB) == LOW)
 {
  delay(100);
  pressLength_milliSeconds = pressLength_milliSeconds + 100;
   Serial.print("ms = ");
   Serial.println(pressLength_milliSeconds);
 }
 if(pressLength_milliSeconds >= optionTwo_milliSeconds){
  digitalWrite(Relay, HIGH);
 }
  pressLength_milliSeconds = 0;
 }




{
  if(digitalRead(ButtonA) == LOW)
  { digitalWrite(Relay, LOW);
    delay(10000);
    digitalWrite(Relay, HIGH);
    
}
 delay(100);
}}

You're getting there.
Once you introduce millis() timing - it's as good a time as any to remove all the delay() calls.

You have a delay(100) - probably to debounce the button. That's where I was hinting at detecting the button state change - rather than testing the button is simply LOW or HIGH

You're testing the button unnecessarily frequently.
When the button's 'state' changes TRUE - start a counter.

When that millis counter reaches the short-press, or long-press interval - do your thing.
Keep track so the button action is only performed once per state - or yoyu can add recurring at a 'repeat' interval if you need it.

so how can i change this in the code?

Give it a try, then we can help.
There are about a hundred exact examples of your problem on the forum.
You’ll need to search and try things - then you’ll learn for next time.

Let’s start with...

unsigned long presstime;
bool buttonstate:
bool prevbuttonstate;

buttonstate = digitalread(buttonpin)// determine if button has changed state...
if (buttonstate != prevbuttonstate) {
  presstime = millis();
  prevbuttonstate = buttonstate;
  // you can do things here to debounce if needed
}
// test the time since the last button state change (long, short, released etc...