Keypress help with project

I am trying to make a simple program that presses the F1 key. The project is a jukebox I am making and in order to add credits, which I want to use a bill acceptor, you have to press F1 in the jukebox program. I have a 110v Mars acceptor that just plugs in and has 2 wires that sends a pulse out when a bill is entered. Although I am struggling with getting my meter to read this right, it keeps jumping around not a constate and is showing (-) around 0.015 I think I will have to test later. But this isn't the problem I am working on, first I need the program working. I will enter my code below now this is the first time trying to write my own program so I'm sure it's all messed up. It will add a credit, but the problem is it adds them constantly and if anything is hooked up to the Arduino or not. I messed with pulseIn as well with no luck. I changed it trying to add HIGH and LOW nothing makes a difference not sure why it just keeps running the loop even though the requirements are not meet, or I guess they are, and I have it programmed wrong. I do have a Leonardo so I could use the keypress. But I have a uno 3 as well if anyone knows how to make it work but from what I read you can't use keypresses and unless there is a way to send a F1 button signal I don't think I can use that. I am typing this from a picture so if there is a mistake I probably just mistype it.

#include <Keyboard.h>
const byte enableCoin = 5;

void setup() {
pinMode(enableCoin, INPUT);
}

void loop() {
if (digitalRead(enableCoin));
delay(500);
Keyboard.press(KEY_F1);
Keyboard.release(Key_F1);
delay(6000);
}

If you were able to compile and upload the sketch using the IDE, then you can also copy and paste the actual code you are using (instead of imperfectly transcribing what you see in a picture).

In the IDE, place the cursor in the sketch, then press Ctrl+Shift+C. Then place the cursor on a new line in the forum comment editor, and press Ctrl+V. After pasting the code, click ⮪ Reply.

If your transcription is accurate, then, at a minimum, there is a coding error in the first statement of your loop() function. The if statement should not end witha semicolon (;), but with a left curly brace ({). You will then need a matching right curly brace (}) at the end of the loop() function.

Also, I am not personally familiar with the Keyboard.h library, but I highly doubt that its defined constants are case-insensitive; thus, either KEY_F1 or Key_F1 is an invalid constant (probably the latter).

I am at work so I don't have my computer to copy it, I know it's possible just wasn't an option tonight. I got the code from a YouTube tutorial. He was using it in a different way but just pressing the arrow keys I think but it was made to type things out for you, and he was just showing how to get the code started. KEY_F1 should be the same as any other key i would think its in the documentation so it should be able to be used but the constant, I'm not positive on I tried different things but that's why I decided to see if someone can point me in the right direction. Most of the post about it was from 2015 and 2016 and links no longer work. The code did upload to the board, although I do get a message like something isn't right with the board. From what I found online more people have had that problem but long as it says upload successful it was ok. I did do the blink sketch just to make sure it was uploading, and it was all correct.

Wrap your code... like this...

Well, when you get back to your computer, try fixing the two errors I pointed out above, and if it still doesn't work, then please post your actual code (using the method described above).

I sure will, and that could have been when I was changing the code around. I will fix that and let you know what happens also will upload the code from my project.

As #grb pointed out, you have a ';' at the end of your if() statement. That makes this

void loop() {
  if (digitalRead(enableCoin));
  delay(500);
  Keyboard.press(KEY_F1);
  Keyboard.release(KEY_F1);
  delay(6000);
}

the same as this

void loop() {
  if (digitalRead(enableCoin)) {
    // do nothing
  }
  delay(500);
  Keyboard.press(KEY_F1);
  Keyboard.release(KEY_F1);
  delay(6000);
}

in other words, your if() statement does nothing.

Ok I see that now thanks for pointing it out and explaining it. Thats probably why it just keep pressing F1 no matter what I changed. I will change it tomorrow and see what happens. Does the rest of the code seem like it would work for what I want? I want a pulse from the bill acceptor to trigger the if statement to press the button. Well 1 time for $1 and multiple for $5 which I know I still have to work on just focused on getting it to work first.

This is the red text everytime I upload a Sketch. I read online it doesnt matter if the upload was complete and sucessful which it does say at the end. It just disconnects my Leonardo sometimes changes ports then connects again.

Sketch uses 5774 bytes (20%) of program storage space. Maximum is 28672 bytes.
Global variables use 226 bytes (8%) of dynamic memory, leaving 2334 bytes for local variables. Maximum is 2560 bytes.
Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
Device code: 0x44

Here is the code from my project,

#include <Keyboard.h>
const byte enableCoin = 5;

void setup()
{
// put your setup code here, to run once:
pinMode(enableCoin, INPUT);

}

void loop()
{
// put your main code here, to run repeatedly:
if (digitalRead(enableCoin))
{
delay(500);
Keyboard.press(KEY_F1);
Keyboard.release(KEY_F1);
delay(6000);
}
}