File: event2.rb

package info (click to toggle)
ruby-sdl 2.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,344 kB
  • ctags: 4,200
  • sloc: cpp: 7,598; ansic: 4,475; ruby: 2,258; sh: 102; makefile: 97
file content (34 lines) | stat: -rw-r--r-- 679 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'sdl'

SDL.init( SDL::INIT_VIDEO )
screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
SDL::WM::set_caption $0,$0

loop do
  while event=SDL::Event.poll 
    case event
    when SDL::Event::Active
      print "Active ", (event.gain)?"gain":"lost","\n"
    when SDL::Event::KeyDown
      print "KeyDown sym:#{event.sym} mod:#{event.mod}","\n"
      if event.sym==SDL::Key::A then
	e=SDL::Event::KeyDown.new
	e.sym=3333
	e.mod=3333
	e.press=true
        e.unicode=200
	SDL::Event.push(e)
      end
    when SDL::Event::KeyUp
      print "KeyUp sym:#{event.sym} mod:#{event.mod}","\n"
      
    when SDL::Event::Quit
      exit
      
    end
  end

  sleep 0.05
end