problems programming my infrared remote controller

Hello, I am a beginner with Arduino and I started doing some projects and I am trying to do that with a mado (infrared remote controller) and the infrared led (infrared reciver 1838t) to activate or deactivate the alarm that I have made with the distance sensor (hc- SR04), and I can activate it by pressing the button that I define and it starts to run, Now the problem is that I don't know how to deactivate it by pressing that same button or another, what I want is to be able to activate it and deactivate it with the same button, and to the other buttons add another functionality, I tried a switch case but it was executed only once when I pressed the button, I leave the code for someone to help me.

#include <IRremote.h>

#define trigPin 9
#define echoPin 10
const int RECV_PIN = 7;
const int ledPinR = 4 ;
const int ledPinY = 5 ;
const int buzzer = 11;
int cont=1;
long duration;
int distance;
//const int ledPinG = 6 ;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(ledPinR, OUTPUT);
pinMode(ledPinY, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzer, OUTPUT);
}

void loop(){
if (irrecv.decode(&results)){

if (results.value == 0xFFC23D /0XFFFFFFFF/){
digitalWrite(trigPin, LOW);
delay(90);
// Trigger the sensor by setting the trigPin high for 10 microseconds:
digitalWrite(trigPin, HIGH);
delay(40);
digitalWrite(trigPin, LOW);
// Read the echoPin, pulseIn() returns the duration (length of the pulse) in microseconds:
duration = pulseIn(echoPin, HIGH);
cont++;

// Calculo la distancia
distance= duration*0.034/2;
if (distance< 50){
alarma(buzzer);
parpadeoLed(ledPinR);
delay(10);
parpadeoLed(ledPinY);
//digitalWrite(ledPinY, LOW);
Serial.print("PELIGRO ");
}
else{

digitalWrite(ledPinR, LOW);
digitalWrite(ledPinY, HIGH);

digitalWrite(buzzer, LOW);
}
Serial.print("Alarma activa ");
Serial.print("distancia = ");
Serial.print(distance);
Serial.println(" cm");
Serial.println(cont);
}

}}

void alarma(int buzzer){
digitalWrite(buzzer, HIGH);
delay(10);
digitalWrite(buzzer, LOW);
delay(10);
digitalWrite(buzzer, HIGH);
delay(50);
digitalWrite(buzzer, LOW);
delay(50);
digitalWrite(buzzer, HIGH);
delay(10);
digitalWrite(buzzer, LOW);
delay(10);
digitalWrite(buzzer, HIGH);
delay(30);

}
void parpadeoLed(int ledPinR){
digitalWrite(ledPinR, HIGH);
delay(10);
digitalWrite(ledPinR, LOW);
delay(10);
digitalWrite(ledPinR, HIGH);
delay(20);
digitalWrite(ledPinR, LOW);
delay(20);
digitalWrite(ledPinR, HIGH);
delay(20);
digitalWrite(ledPinR, LOW);
delay(20);
digitalWrite(ledPinR, HIGH);
delay(20);
digitalWrite(ledPinR, LOW);
delay(20);
digitalWrite(ledPinR, HIGH);
delay(20);
digitalWrite(ledPinR, LOW);
delay(20);
digitalWrite(ledPinR, HIGH);
delay(20);
digitalWrite(ledPinR, LOW);
delay(20);
digitalWrite(ledPinR, HIGH);
delay(20);
digitalWrite(ledPinR, LOW);
delay(20);
}

As written

void loop()
{
  if (irrecv.decode(&results))
  {
    if (results.value == 0xFFC23D /*0XFFFFFFFF*/)
    {
     //dependent code in here
    }

whenever the value is received then the program executes the dependent code but you need to one of two different things depending on what happened the last time it was retrieved so try this

Declare a new boolean variable, let's name it OKToRun then do this

void loop()
{
  if (irrecv.decode(&results))
  {
    if (results.value == 0xFFC23D /*0XFFFFFFFF*/)
    {
      OKToRun = !OKToRun;  //flip the state of the variable
    }

Then you can do

if (OKToRun == true)
  {
    //code here to activate the sensor
  }
else
  {
    //code here to deactivate the sensor
  }