I have prepared for you an example of how you wanted it. If you press the same keys twice in a row, the frame color changes to red, otherwise black.
Attention! This example uses kernal routines. There is nothing wrong with that. But there is a lower way to do this without using the $ffd2 (Output Vector, chrout) and $ffe4 (Get From Keyboad) kernel calls. But since this is a lot harder to understand, I preferred this example.
If you want to know what happens behind the scenes (kernel calls), you can easily track ROM kernel codes from the AAY64 documentation. Here are the links:
AAY Home Page: http://www.the-dreams.de/aay.html
AAY64 HTML Online Version: http://unusedino.de/ec64/technical/aay/c64/
Kernal ROM List: http://unusedino.de/ec64/technical/aay/c64/krnromma.htm
$ffd2 (Output vector, chrout): http://unusedino.de/ec64/technical/aay/c64/romffd2.htm
$ffe4 (Get From Keyboad): http://unusedino.de/ec64/technical/aay/c64/romffe4.htm
You can browse deeper by clicking links to opcodes and addresses.
Here is a sample code. You can compile this code with ACME Crossassembler , which you can find here → http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/acme/
!to "keycomp.prg",cbm zpBuffer = $fa ; $fa-$fb are reserved for 2 bytes of key buffer * = $0801 !byte $0c, $08, $00, $00, $9e, $32, $30, $36, $31, $00, $00, $00 * = $080d ; key buffer initialization ldx