Comparing function to string inside while loop

Hi, I'm new to Arduino and programming in general so sorry if this is a stupid question.

Using the Keypad library, I'm trying to compare a function that fetches the status of a key to one of the strings that the function returns, inside a while loop and it returns an error message. Being a new programmer, I'm not sure what I am doing wrong. Any insight is greatly appreciated. Thanks in advance.

Here is the line: while(KeyState getState()==PRESSED) {}

Here is the error message:

Arduino: 1.6.9 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/DMac/Documents/Arduino/Keypad/KeypadSketch/KeypadSketch.ino: In function 'void loop()':
KeypadSketch:30: error: expected primary-expression before 'getState'
     while(KeyState getState()==PRESSED) {}
                    ^
KeypadSketch:30: error: expected ')' before 'getState'
KeypadSketch:30: error: 'getState' was not declared in this scope
     while(KeyState getState()==PRESSED) {}
                             ^
KeypadSketch:30: error: expected ';' before ')' token
     while(KeyState getState()==PRESSED) {}
                                       ^
KeypadSketch:35: error: expected primary-expression before 'getState'
   while(KeyState getState()==PRESSED) {}
                  ^
KeypadSketch:35: error: expected ')' before 'getState'
KeypadSketch:35: error: 'getState' was not declared in this scope
   while(KeyState getState()==PRESSED) {}
                           ^
KeypadSketch:35: error: expected ';' before ')' token
   while(KeyState getState()==PRESSED) {}
                                     ^
KeypadSketch:40: error: expected primary-expression before 'getState'
     while(KeyState getState()==PRESSED) {}
                    ^
KeypadSketch:40: error: expected ')' before 'getState'
KeypadSketch:40: error: 'getState' was not declared in this scope
     while(KeyState getState()==PRESSED) {}
                             ^
KeypadSketch:40: error: expected ';' before ')' token
     while(KeyState getState()==PRESSED) {}
                                       ^
KeypadSketch:45: error: expected primary-expression before '{' token
   if(myPassword=={5,2,5,3})
                  ^
KeypadSketch:45: error: expected ')' before '{' token
exit status 1
expected primary-expression before 'getState'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

If you need it, here is the whole program:

//http://playground.arduino.cc/Code/Keypad

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6, 9}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);
}
  
void loop(){
 int myPassword[4]; 
  char waitForKey();
  myPassword[0] = customKeypad.getKey();
  tone(10,941,250);
  Serial.println(myPassword[0]);
    while(KeyState getState()==PRESSED) {}
    char waitForKey();
    myPassword[1] = customKeypad.getKey();
    tone(10,941,250);
    Serial.println(myPassword[1]);
  while(KeyState getState()==PRESSED) {}
  char waitForKey();
  myPassword[2] = customKeypad.getKey();
  tone(10,941,250);
  Serial.println(myPassword[2]);
    while(KeyState getState()==PRESSED) {}
    char waitForKey();
    myPassword[3] = customKeypad.getKey();
    tone(10,941,250);
    Serial.println(myPassword[3]);
  if(myPassword=={5,2,5,3})
  { tone(10,1500,250);
  delay(25);
  tone(10,1750,250);
   delay(25);
  tone(10,2000,250);
   delay(25);
    /*relay*/ }
    else {
   tone(10,300,250);
   delay(25);
   tone(10,300,250);
   delay(25);
   tone(10,300,250);
   delay(25);
}}
while( getState()==PRESSED) {}

You're not trying to compare a function, you're trying to compare the function's return value

You declare the object "customKeypad".
To call a function of that object, you should do : customKeypad.getState()

I'm not sure if this will work, since the return value of .getState() is an enumerator. That means it is almost an integer, so I think it will work.

  while(customKeypad.getState()==PRESSED)

An object is the data and functions in a single package. The goal of an object is that it is seperated from other things. Therefor the compiler must know every time which object is used. Just a getState() will not work, and the declaration with 'KeyState' should not be used like that.

Where did you get the library from ?
If you look at all the examples here : GitHub - Chris--A/Keypad: A version of the keypad library found in Wiring. This is just a copy made compatible with the Arduino IDE library manager.
then you found the use of .getStat().
Perhaps you might need to declare an extra variable for the key state.

Koepel:
You declare the object "customKeypad".
To call a function of that object, you should do : customKeypad.getState()

  while(customKeypad.getState()==PRESSED)

An object is the data and functions in a single package. The goal of an object is that it is seperated from other things. Therefor the compiler must know every time which object is used. Just a getState() will not work, and the declaration with 'KeyState' should not be used like that.

Thank you!! I appreciate the help

char waitForKey();

Don't do that either