When a key is pressed you set a flag in the key_flag file that corresponds to the key. When the scan routine comes around the next time, it looks at the key flags and if it sees a flag=1 the corresponding LED is illuminated via the LED_flag file. When the scan routine comes around the next time it sees the LED flag=1 and turns on the LED.
When the scan routine comes around a few scans later it sees if the switch is still pressed. If not it makes the flag=0. The next scan sees the flag=0 and the next time it turns off the LED. If the LED is the flashing LED, it flashes. If not, it just illuminates.
When the scan routine comes around a few scans later it sees if the switch is still pressed. If not it makes the flag=0. The next scan sees the flag=0 and the next time it turns off the LED. If the LED is the flashing LED, it flashes. If not, it just illuminates.