-
Notifications
You must be signed in to change notification settings - Fork 10
/
modifiers.cr
62 lines (57 loc) · 1.68 KB
/
modifiers.cr
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module CrystGLFW
module Event
# The Modifiers module encapsulates the instance variables and interfaces for Events that support modifier keys.
module Modifiers
@mod_shift : Bool = false
@mod_control : Bool = false
@mod_alt : Bool = false
@mod_super : Bool = false
private def set_modifiers(modifiers : Int32)
@mod_shift = modifiers.bit(0) == 1
@mod_control = modifiers.bit(1) == 1
@mod_alt = modifiers.bit(2) == 1
@mod_super = modifiers.bit(3) == 1
end
# Returns true if the shift key was held down as a modifier. False otherwise.
#
# ```
# window.on_key do |key_event|
# puts "The shift key was held down as a modifier." if key_event.shift?
# end
# ```
def shift?
@mod_shift
end
# Returns true if the control key was held down as a modifier. False otherwise.
#
# ```
# window.on_key do |key_event|
# puts "The control key was held down as a modifier." if key_event.control?
# end
# ```
def control?
@mod_control
end
# Returns true if the alt key was held down as a modifier. False otherwise.
#
# ```
# window.on_key do |key_event|
# puts "The alt key was held down as a modifier." if key_event.alt?
# end
# ```
def alt?
@mod_alt
end
# Returns true if the super key was held down as a modifier. False otherwise.
#
# ```
# window.on_key do |key_event|
# puts "The super key was held down as a modifier." if key_event.super?
# end
# ```
def super?
@mod_super
end
end
end
end