Skip to content

Add support for num/caps lock #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions dragon/keyboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ def self.sdl_to_key raw_key, modifier
return nil unless (raw_key >= 0 && raw_key <= 255) ||
KeyboardKeys.char_to_method_hash[raw_key]

@num_lock_mode = (modifier & (4096)) != 0 # num lock is on?
@caps_lock_mode = (modifier & (8192)) != 0 # caps lock is on?

char = KeyboardKeys.char_with_shift raw_key, modifier
names = KeyboardKeys.char_to_method char, raw_key
names << :alt if KeyboardKeys.modifier_alt? modifier
Expand Down Expand Up @@ -464,6 +467,7 @@ def self.char_to_method_hash
1073742098 => [:ac_bookmarks]
}
end


def self.method_to_key_hash
return @method_to_key_hash if @method_to_key_hash
Expand Down Expand Up @@ -494,6 +498,14 @@ def self.char_to_method char, int = nil
methods ? methods.dup : [char.to_sym || int]
end

def self.num_lock_mode
@num_lock_mode ||= false
end

def self.caps_lock_mode
@caps_lock_mode ||= false
end

def clear
set truthy_keys, false
@keycodes.clear
Expand Down Expand Up @@ -757,6 +769,20 @@ def down_arrow
@key_down.down || @key_held.down || false
end

# The num lock is on
#
# @return [Boolean]
def num_lock?
KeyboardKeys.num_lock_mode
end

# The caps lock is on
#
# @return [Boolean]
def caps_lock?
KeyboardKeys.caps_lock_mode
end

# Clear all current key presses.
#
# @return [void]
Expand Down