Skip to content

Instantly share code, notes, and snippets.

@atomicules
Created November 12, 2009 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomicules/232905 to your computer and use it in GitHub Desktop.
Save atomicules/232905 to your computer and use it in GitHub Desktop.
# 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