Sha256: bb79eca90eb635d70b99e1124b64cf6800efd3eadcb12645bf10891fed633108

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

module Mac
  module EventMonitor
    class KeyboardEvent < Event
      attr_reader :keycode, :flags

      def initialize(type, time, location, keycode, flags)
        super(type, time, location)

        @keycode = keycode.to_i
        @flags   = flags.to_i(16)
      end

      def shift_key?
        check_flag(16) || check_flag(17)
      end

      def ctrl_key?
        check_flag(18)
      end

      def alt_key?
        check_flag(19)
      end

      def command_key?
        check_flag(20)
      end

      def num_pad_key?
        check_flag(21)
      end

      def help_key?
        check_flag(22)
      end

      def function_key?
        check_flag(23)
      end

      def data
        super + [keycode, flags.to_s(16)]
      end

      private

      def check_flag(shift)
        !(flags & (1 << shift)).zero?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mac-event-monitor-0.2.1 lib/mac-event-monitor/event/keyboard_event.rb
mac-event-monitor-0.2.0 lib/mac-event-monitor/event/keyboard_event.rb