UNO,4x3 keypad and a 8 channel relay

I'm trying to figure out how to use my UNO and a 4x3 keypad to run a 8 channel relay. I want each key to turn on a different relay but I also want my * key to be a all on and my # key to be an all off. I'd also like to be able to press the key that is on again to turn just that relay off while leaving the other relays on. I'm new to arduino and coding so its been a difficult task. Any help would be greatly appreciated.

Someone else has done all the thinking for you:
http://playground.arduino.cc/code/Keypad
On that page, in the Download section, you see the file "keypad.zip". That's the library you need. It comes with examples included.
If you can't make it work, upload your sketch so we can see how far you got.

I have downloaded the keypad files. This is as far as I have gotten not real sure if I'm on the right path thanks for the help.

/* @file EventSerialKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates using the KeypadEvent.
|| #
*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;
byte ledPin1 = 12;
byte ledPin2 = 11;
byte ledPin3 = 10;

boolean blink = false;
boolean ledPin_state;

void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Sets the digital pin as output.
digitalWrite(ledPin, HIGH); // Turn the LED on.
digitalWrite(ledPin1,HIGH);
digitalWrite(ledPin2,HIGH);
digitalWrite(ledPin3,HIGH); // Store initial LED state. HIGH when LED is on.
keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}

void loop(){
char key = keypad.getKey();

if (key) {
Serial.println(key);
}
if (blink){
digitalWrite(ledPin,!digitalRead(ledPin)); // Change the ledPin from Hi2Lo or Lo2Hi.
delay(100);
}
}

// Taking care of some special events.
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
case PRESSED:
if (key == '1') {
digitalWrite(ledPin,LOW);
}

if (key == '2') {
digitalWrite(ledPin2,LOW);
}

if (key == '3') {
digitalWrite(ledPin3,LOW);
}
if (key == '4') {
digitalWrite(ledPin1,LOW);
// Remember LED state, lit or unlit.
if (key == '#') {
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin2,HIGH);
digitalWrite(ledPin3,HIGH);
digitalWrite(ledPin1,HIGH);

}
}
}
}

Yes, you are on the right track.

You used the advanced feature by using the event handler.
If your loop() function doesn't have a lot to do, you could switch the relays/led also in the loop() function.
I don't know what 'blink' is doing, not much at the moment.

From a programmers view, you could make a function for the relay functions.
That would seperate the buttons from the relays.
Relay( 2, TOGGLE);
Relay( 3, ON);
Relay( 4, OFF);
Relay( -1, ALL_ON);
Relay( -1, ALL_OFF);
To be able to 'toggle' a relay, you have to remember the state for every relay in a variable.
The avantage is that you can extend the code easily in the future.
The disadvantage is that the code might get too large for something that is (yet) simple.

With 8 relays, you can set the pin number in an array, and refer to relay 0, or relay 1 and so on.
int pinRelay[] = { 13, 12, 11, 10, A0, A1, A2, A3 }; // use also a few analog inputs as digital output pins.
So instead of relay at pin 13, you would use: pinRelay[0]

ledPin_state = digitalRead(ledPin);

Could I use something like this to be able to remember the state in each relay?

I'm really confused by creating a function in the loop(). This is the best I could come up with I'm not real sure how to create a function I have searched it but still lost! Thanks for any input!

/* @file EventSerialKeypad.pde
 || @version 1.0
 || @author Alexander Brevig
 || @contact alexanderbrevig@gmail.com
 ||
 || @description
 || | Demonstrates using the KeypadEvent.
 || #
 */
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;
byte ledPin1 = 12;
byte ledPin2 = 11; 
byte ledPin3 = 10;


boolean ledPin_state;

void setup(){
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);              // Sets the digital pin as output.
    digitalWrite(ledPin, HIGH);           // Turn the LED on.
    digitalWrite(ledPin1,HIGH);
    digitalWrite(ledPin2,HIGH);
    digitalWrite(ledPin3,HIGH);   // Store initial LED state. HIGH when LED is on.
    keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}

void loop(){
 relayFunction
  Relay( 2, TOGGLE);
  Relay( 3, ON);
  Relay( 4, OFF);
  Relay( -1, ALL_ON);
  Relay( -1, ALL_OFF);
    char key = keypad.getKey();

    if (key) {
        Serial.println(key);
    }
    
}

// Taking care of some special events.
void keypadEvent(KeypadEvent key){
    switch (keypad.getState()){
    case PRESSED:
        if (key == '1') {
            digitalWrite(ledPin,LOW);
             }
             
     if (key == '2') {
            digitalWrite(ledPin2,LOW);
           }
     
     if (key == '3') {
            digitalWrite(ledPin3,LOW);
           }
     if (key == '4') {
            digitalWrite(ledPin1,LOW);
                   // Remember LED state, lit or unlit.
     if (key == '#') {
            digitalWrite(ledPin,HIGH);
            digitalWrite(ledPin2,HIGH);
            digitalWrite(ledPin3,HIGH);
            digitalWrite(ledPin1,HIGH);
            
    }
     }
    }
}

Reading a output pin with digitalRead : Yes.
Reading a pin is always possible, regardless if the pin is output or not. So reading a pin to get its state is possible.
However, it is some kind of 'trick'. So it is better to keep the state in a variable in software.

Your confusing sketch is indeed confusing.
My suggestions are just a few suggestions, if you don't understand it, don't try to implement it. Just forget it, and follow what you think it should be.

If you connect the keypad, can you make the leds go on and off ?

I can only get one relay to turn on but that is it no all on or all off. My # does turn off relay 1.

You send also the buttons to the serial monitor.
If you don't look at the leds, try to get the buttons working by watching the value on the serial monitor.

All the buttons are working in the serial monitor. Still not sure how to make them toggle.

Okay, very good.

What was wrong with this : digitalWrite(ledPin,!digitalRead(ledPin));
You can do that with the '1', '2', '3', '4' buttons.

Maybe later you can change the code and use the state of the relays in a variable. But at the moment, let's make those leds toggle.

The all off "#" and all on "*" work with relay 1 but none of the other relays will work. I got some help from another member to get this code to work.

/* @file EventSerialKeypad.pde
 || @version 1.0
 || @author Alexander Brevig
 || @contact alexanderbrevig@gmail.com
 ||
 || @description
 || | Demonstrates using the KeypadEvent.
 || #
 */
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;
byte ledPin1 = 12;
byte ledPin2 = 11; 
byte ledPin3 = 10;


boolean ledPin_state;

void setup(){
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);              // Sets the digital pin as output.
    digitalWrite(ledPin, HIGH);           // Turns the relay off.
    digitalWrite(ledPin1,HIGH);
    digitalWrite(ledPin2,HIGH);
    digitalWrite(ledPin3,HIGH);   
    keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}

void loop(){
    char key = keypad.getKey();

    if (key) {
        Serial.println(key);
    }
    
}

// Taking care of some special events.
void keypadEvent(KeypadEvent key){
    switch (keypad.getState()){
    case PRESSED:
    
    if (key == '1') 
    {
      digitalWrite(ledPin,LOW);
    }

    if (key == '2') 
    {
      digitalWrite(ledPin1,LOW);
    }

    if (key == '3') 
    {
      digitalWrite(ledPin3,LOW);
    }
    
    if (key == '4') 
    {
      digitalWrite(ledPin2,LOW);
      // Remember LED state, lit or unlit.
    }
    
    if (key == '#') 
    {
      digitalWrite(ledPin,HIGH);   // turns all relays off
      digitalWrite(ledPin2,HIGH);
      digitalWrite(ledPin3,HIGH);
      digitalWrite(ledPin1,HIGH);
    }
    
    if (key == '*') 
    {
      digitalWrite(ledPin,LOW);      // Turns all relays on 
      digitalWrite(ledPin1,LOW); 
      digitalWrite(ledPin2,LOW); 
      digitalWrite(ledPin3,LOW);
    } 
    break;
     }                 
    }

You only have the one pinMode for the first relay, where are the other 3? "pinMode(ledPin, OUTPUT);"

I don't know how I missed that. Its fixed and solved several problems thanks.