pub fn update_keys(ch8: &mut Chip8, events: &mut EventPump) -> Result<(), ()> {
    for event in events.poll_iter() {
        match event {
            Event::KeyDown { keycode: Some(Keycode::Num1), .. } => { ch8.update_key(0, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Num2), .. } => { ch8.update_key(1, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Num3), .. } => { ch8.update_key(2, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Num4), .. } => { ch8.update_key(3, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Q), .. } => { ch8.update_key(4, true)?; },
            Event::KeyDown { keycode: Some(Keycode::W), .. } => { ch8.update_key(5, true)?; },
            Event::KeyDown { keycode: Some(Keycode::E), .. } => { ch8.update_key(6, true)?; },
            Event::KeyDown { keycode: Some(Keycode::R), .. } => { ch8.update_key(7, true)?; },
            Event::KeyDown { keycode: Some(Keycode::A), .. } => { ch8.update_key(8, true)?; },
            Event::KeyDown { keycode: Some(Keycode::S), .. } => { ch8.update_key(9, true)?; },
            Event::KeyDown { keycode: Some(Keycode::D), .. } => { ch8.update_key(0xA, true)?; },
            Event::KeyDown { keycode: Some(Keycode::F), .. } => { ch8.update_key(0xB, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Y), .. } => { ch8.update_key(0xC, true)?; },
            Event::KeyDown { keycode: Some(Keycode::X), .. } => { ch8.update_key(0xD, true)?; },
            Event::KeyDown { keycode: Some(Keycode::C), .. } => { ch8.update_key(0xE, true)?; },
            Event::KeyDown { keycode: Some(Keycode::V), .. } => { ch8.update_key(0xF, true)?; },

            
            Event::KeyUp { keycode: Some(Keycode::Num1), .. } => { ch8.update_key(0, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Num2), .. } => { ch8.update_key(1, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Num3), .. } => { ch8.update_key(2, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Num4), .. } => { ch8.update_key(3, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Q), .. } => { ch8.update_key(4, false)?; },
            Event::KeyUp { keycode: Some(Keycode::W), .. } => { ch8.update_key(5, false)?; },
            Event::KeyUp { keycode: Some(Keycode::E), .. } => { ch8.update_key(6, false)?; },
            Event::KeyUp { keycode: Some(Keycode::R), .. } => { ch8.update_key(7, false)?; },
            Event::KeyUp { keycode: Some(Keycode::A), .. } => { ch8.update_key(8, false)?; },
            Event::KeyUp { keycode: Some(Keycode::S), .. } => { ch8.update_key(9, false)?; },
            Event::KeyUp { keycode: Some(Keycode::D), .. } => { ch8.update_key(0xA, false)?; },
            Event::KeyUp { keycode: Some(Keycode::F), .. } => { ch8.update_key(0xB, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Y), .. } => { ch8.update_key(0xC, false)?; },
            Event::KeyUp { keycode: Some(Keycode::X), .. } => { ch8.update_key(0xD, false)?; },
            Event::KeyUp { keycode: Some(Keycode::C), .. } => { ch8.update_key(0xE, false)?; },
            Event::KeyUp { keycode: Some(Keycode::V), .. } => { ch8.update_key(0xF, false)?; },
            _ => ()
        }
    }
    Ok(())
}
/// Updates CHIP-8 keystates from an SDL EventPump
Updates CHIP-8 keystates from an SDL EventPump
Updates CHIP - 8 keystates from an SDL EventPump
pub fn update_keys(ch8: &mut Chip8, events: &mut EventPump) -> Result<(), ()> {
    for event in events.poll_iter() {
        match event {
            Event::KeyDown { keycode: Some(Keycode::Num1), .. } => { ch8.update_key(0, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Num2), .. } => { ch8.update_key(1, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Num3), .. } => { ch8.update_key(2, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Num4), .. } => { ch8.update_key(3, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Q), .. } => { ch8.update_key(4, true)?; },
            Event::KeyDown { keycode: Some(Keycode::W), .. } => { ch8.update_key(5, true)?; },
            Event::KeyDown { keycode: Some(Keycode::E), .. } => { ch8.update_key(6, true)?; },
            Event::KeyDown { keycode: Some(Keycode::R), .. } => { ch8.update_key(7, true)?; },
            Event::KeyDown { keycode: Some(Keycode::A), .. } => { ch8.update_key(8, true)?; },
            Event::KeyDown { keycode: Some(Keycode::S), .. } => { ch8.update_key(9, true)?; },
            Event::KeyDown { keycode: Some(Keycode::D), .. } => { ch8.update_key(0xA, true)?; },
            Event::KeyDown { keycode: Some(Keycode::F), .. } => { ch8.update_key(0xB, true)?; },
            Event::KeyDown { keycode: Some(Keycode::Y), .. } => { ch8.update_key(0xC, true)?; },
            Event::KeyDown { keycode: Some(Keycode::X), .. } => { ch8.update_key(0xD, true)?; },
            Event::KeyDown { keycode: Some(Keycode::C), .. } => { ch8.update_key(0xE, true)?; },
            Event::KeyDown { keycode: Some(Keycode::V), .. } => { ch8.update_key(0xF, true)?; },
            Event::KeyUp { keycode: Some(Keycode::Num1), .. } => { ch8.update_key(0, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Num2), .. } => { ch8.update_key(1, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Num3), .. } => { ch8.update_key(2, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Num4), .. } => { ch8.update_key(3, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Q), .. } => { ch8.update_key(4, false)?; },
            Event::KeyUp { keycode: Some(Keycode::W), .. } => { ch8.update_key(5, false)?; },
            Event::KeyUp { keycode: Some(Keycode::E), .. } => { ch8.update_key(6, false)?; },
            Event::KeyUp { keycode: Some(Keycode::R), .. } => { ch8.update_key(7, false)?; },
            Event::KeyUp { keycode: Some(Keycode::A), .. } => { ch8.update_key(8, false)?; },
            Event::KeyUp { keycode: Some(Keycode::S), .. } => { ch8.update_key(9, false)?; },
            Event::KeyUp { keycode: Some(Keycode::D), .. } => { ch8.update_key(0xA, false)?; },
            Event::KeyUp { keycode: Some(Keycode::F), .. } => { ch8.update_key(0xB, false)?; },
            Event::KeyUp { keycode: Some(Keycode::Y), .. } => { ch8.update_key(0xC, false)?; },
            Event::KeyUp { keycode: Some(Keycode::X), .. } => { ch8.update_key(0xD, false)?; },
            Event::KeyUp { keycode: Some(Keycode::C), .. } => { ch8.update_key(0xE, false)?; },
            Event::KeyUp { keycode: Some(Keycode::V), .. } => { ch8.update_key(0xF, false)?; },
            _ => ()
        }
    }
    Ok(())
}
pub fn update_keys ( ch8 : & mut Chip8 , events : & mut EventPump ) -> Result < ( ) , ( ) > { for event in events . poll_iter ( ) { match event { Event :: KeyDown { keycode : Some ( Keycode :: Num1 ) , .. } => { ch8 . update_key ( 0 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: Num2 ) , .. } => { ch8 . update_key ( 1 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: Num3 ) , .. } => { ch8 . update_key ( 2 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: Num4 ) , .. } => { ch8 . update_key ( 3 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: Q ) , .. } => { ch8 . update_key ( 4 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: W ) , .. } => { ch8 . update_key ( 5 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: E ) , .. } => { ch8 . update_key ( 6 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: R ) , .. } => { ch8 . update_key ( 7 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: A ) , .. } => { ch8 . update_key ( 8 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: S ) , .. } => { ch8 . update_key ( 9 , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: D ) , .. } => { ch8 . update_key ( 0xA , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: F ) , .. } => { ch8 . update_key ( 0xB , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: Y ) , .. } => { ch8 . update_key ( 0xC , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: X ) , .. } => { ch8 . update_key ( 0xD , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: C ) , .. } => { ch8 . update_key ( 0xE , true ) ? ; } , Event :: KeyDown { keycode : Some ( Keycode :: V ) , .. } => { ch8 . update_key ( 0xF , true ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: Num1 ) , .. } => { ch8 . update_key ( 0 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: Num2 ) , .. } => { ch8 . update_key ( 1 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: Num3 ) , .. } => { ch8 . update_key ( 2 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: Num4 ) , .. } => { ch8 . update_key ( 3 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: Q ) , .. } => { ch8 . update_key ( 4 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: W ) , .. } => { ch8 . update_key ( 5 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: E ) , .. } => { ch8 . update_key ( 6 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: R ) , .. } => { ch8 . update_key ( 7 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: A ) , .. } => { ch8 . update_key ( 8 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: S ) , .. } => { ch8 . update_key ( 9 , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: D ) , .. } => { ch8 . update_key ( 0xA , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: F ) , .. } => { ch8 . update_key ( 0xB , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: Y ) , .. } => { ch8 . update_key ( 0xC , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: X ) , .. } => { ch8 . update_key ( 0xD , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: C ) , .. } => { ch8 . update_key ( 0xE , false ) ? ; } , Event :: KeyUp { keycode : Some ( Keycode :: V ) , .. } => { ch8 . update_key ( 0xF , false ) ? ; } , _ => ( ) } } Ok ( ( ) ) }
Updates CHIP-8 keystates from an SDL EventPump
Updates CHIP - 8 keystates from an SDL EventPump
ch8
&mut Chip8
events
&mut EventPump
ch8
&mut Chip8
events
&mut EventPump