Created
November 12, 2009 13:49
-
-
Save atomicules/232905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple app to test Keypress, Keydown and Keyup functionality | |
# Reports key being pressed and changes colour with change in state | |
Shoes.app do | |
@keypress = para "Keypress: " | |
para "\n" | |
@keydown = para "Keydown:" | |
para "\n" | |
@keyup = para "Keyup: " | |
@kpff = 0 | |
@kdff = 0 | |
@kuff = 0 | |
def changecolour(k) | |
if k == 'kp' | |
if @kpff == 0 | |
@keypress.style(:stroke =>red) | |
else | |
@keypress.style(:stroke => yellow) | |
end | |
@kpff = 1 - @kpff | |
end | |
if k == 'kd' | |
if @kdff == 0 | |
@keydown.style(:stroke =>blue) | |
else | |
@keydown.style(:stroke => cyan) | |
end | |
@kdff = 1 - @kdff | |
end | |
if k == 'ku' | |
if @kuff == 0 | |
@keyup.style(:stroke =>green) | |
else | |
@keyup.style(:stroke => magenta) | |
end | |
@kuff = 1 - @kdff | |
end | |
end | |
keyup do |k| | |
@keyup.replace "Keyup: #{k.inspect}" | |
changecolour('ku') | |
end | |
keydown do |k| | |
@keydown.replace "Keydown: #{k.inspect}" | |
changecolour('kd') | |
end | |
keypress do |k| | |
@keypress.replace "Keypress: #{k.inspect}" | |
changecolour('kp') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment