Navigation Menu

Skip to content

Commit

Permalink
Added the ability to combine the modifier keys of all keyboards plugg…
Browse files Browse the repository at this point in the history
…in in when the program starts
  • Loading branch information
Grockit committed Sep 8, 2009
1 parent d544178 commit d58c552
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 86 deletions.
98 changes: 35 additions & 63 deletions control_freak.iws
Expand Up @@ -2,18 +2,16 @@
<project relativePaths="false" version="4">
<component name="ChangeListManager">
<list default="true" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/framework/ControlFreak.xcodeproj/project.pbxproj" afterPath="$PROJECT_DIR$/framework/ControlFreak.xcodeproj/project.pbxproj" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/framework/EventTap.h" afterPath="$PROJECT_DIR$/framework/EventTap.h" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/framework/EventTap.m" afterPath="$PROJECT_DIR$/framework/EventTap.m" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/control_freak/event.rb" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/control_freak/event_tap.rb" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/control_freak.iws" afterPath="$PROJECT_DIR$/control_freak.iws" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/control_freak/subscription_node.rb" afterPath="$PROJECT_DIR$/lib/control_freak/subscription_node.rb" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/control_freak/xkeys_pedal.rb" afterPath="$PROJECT_DIR$/lib/control_freak/xkeys_pedal.rb" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/control_freak/ddhid_keyboard.rb" afterPath="$PROJECT_DIR$/lib/control_freak/ddhid_keyboard.rb" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/control_freak.rb" afterPath="$PROJECT_DIR$/lib/control_freak.rb" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/control_freak/xkeys_pedal.rb" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/control_freak/ddhid_keyboard.rb" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/control_freak/subscription_node.rb" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/control_freak/event.rb" afterPath="$PROJECT_DIR$/lib/control_freak/event.rb" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/framework/ControlFreak.xcodeproj/grockit.pbxuser" afterPath="$PROJECT_DIR$/framework/ControlFreak.xcodeproj/grockit.pbxuser" />
</list>
<ignored path=".idea/workspace.xml" />
<ignored path="control_freak.iws" />
<ignored path=".idea/workspace.xml" />
</component>
<component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
<component name="CreatePatchCommitExecutor">
Expand Down Expand Up @@ -64,55 +62,28 @@
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="event.rb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/control_freak/event.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="27" column="0" selection-start="599" selection-end="599" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="event_tap.rb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/control_freak/event_tap.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="10" column="20" selection-start="175" selection-end="175" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="control_freak.rb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/control_freak.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="27" column="36" selection-start="729" selection-end="729" vertical-scroll-proportion="0.0">
<state line="27" column="0" selection-start="707" selection-end="707" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="subscription_node.rb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/control_freak/subscription_node.rb">
<file leaf-file-name="ddhid_keyboard.rb" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/control_freak/ddhid_keyboard.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="6" selection-start="6" selection-end="22" vertical-scroll-proportion="0.0">
<state line="76" column="15" selection-start="1239" selection-end="1239" vertical-scroll-proportion="0.06993007">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="xkeys_pedal.rb" pinned="false" current="true" current-in-tab="true">
<file leaf-file-name="xkeys_pedal.rb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/control_freak/xkeys_pedal.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="4" column="0" selection-start="76" selection-end="76" vertical-scroll-proportion="0.08269858">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ddhid_keyboard.rb" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/control_freak/ddhid_keyboard.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="22" column="23" selection-start="440" selection-end="456" vertical-scroll-proportion="0.0">
<state line="31" column="2" selection-start="768" selection-end="768" vertical-scroll-proportion="-22.56">
<folding />
</state>
</provider>
Expand Down Expand Up @@ -225,6 +196,7 @@
</navigator>
</component>
<component name="PropertiesComponent">
<property name="GoToClass.includeJavaFiles" value="false" />
<property name="project.structure.proportion" value="0.15" />
<property name="MemberChooser.copyJavadoc" value="false" />
<property name="project.structure.last.edited" value="Global Libraries" />
Expand Down Expand Up @@ -325,25 +297,25 @@
</component>
<component name="ToolWindowManager">
<frame x="-1" y="22" width="2560" height="1574" extended-state="0" />
<editor active="true" />
<editor active="false" />
<layout>
<window_info id="Dataflow to this" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" />
<window_info id="Dataflow to this" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24970132" sideWeight="0.66643786" order="0" side_tool="false" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32875773" sideWeight="0.5" order="1" side_tool="false" />
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24970132" sideWeight="0.66643786" order="0" side_tool="false" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32815665" sideWeight="0.5" order="1" side_tool="false" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" />
<window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" />
<window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32944405" sideWeight="0.5" order="2" side_tool="false" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" />
</layout>
Expand Down Expand Up @@ -373,16 +345,16 @@
<breakpoint-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/lib/control_freak/event.rb">
<entry file="file://$PROJECT_DIR$/lib/control_freak/subscription_node.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="27" column="0" selection-start="599" selection-end="599" vertical-scroll-proportion="0.0">
<state line="5" column="0" selection-start="99" selection-end="99" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/control_freak/ddhid_keyboard.rb">
<entry file="file://$PROJECT_DIR$/lib/control_freak/event.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="22" column="23" selection-start="440" selection-end="456" vertical-scroll-proportion="0.0">
<state line="1" column="22" selection-start="34" selection-end="34" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
Expand All @@ -394,23 +366,23 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/control_freak.rb">
<entry file="file://$PROJECT_DIR$/lib/control_freak/xkeys_pedal.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="27" column="36" selection-start="729" selection-end="729" vertical-scroll-proportion="0.0">
<state line="31" column="2" selection-start="768" selection-end="768" vertical-scroll-proportion="-22.56">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/control_freak/subscription_node.rb">
<entry file="file://$PROJECT_DIR$/lib/control_freak.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="6" selection-start="6" selection-end="22" vertical-scroll-proportion="0.0">
<state line="27" column="0" selection-start="707" selection-end="707" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/control_freak/xkeys_pedal.rb">
<entry file="file://$PROJECT_DIR$/lib/control_freak/ddhid_keyboard.rb">
<provider selected="true" editor-type-id="text-editor">
<state line="4" column="0" selection-start="76" selection-end="76" vertical-scroll-proportion="0.08269858">
<state line="76" column="15" selection-start="1239" selection-end="1239" vertical-scroll-proportion="0.06993007">
<folding />
</state>
</provider>
Expand Down
18 changes: 9 additions & 9 deletions framework/ControlFreak.xcodeproj/grockit.pbxuser
Expand Up @@ -30,17 +30,17 @@
PBXFileDataSource_Target_ColumnID,
);
};
PBXPerProjectTemplateStateSaveDate = 273792197;
PBXWorkspaceStateSaveDate = 273792197;
PBXPerProjectTemplateStateSaveDate = 274121850;
PBXWorkspaceStateSaveDate = 274121850;
};
perUserProjectItems = {
697ED5D51051BD4200E1EF5C /* PBXTextBookmark */ = 697ED5D51051BD4200E1EF5C /* PBXTextBookmark */;
698838FF1051826A0022D04C /* PBXTextBookmark */ = 698838FF1051826A0022D04C /* PBXTextBookmark */;
698839001051826A0022D04C /* PBXTextBookmark */ = 698839001051826A0022D04C /* PBXTextBookmark */;
6988391B10518B870022D04C /* PBXTextBookmark */ = 6988391B10518B870022D04C /* PBXTextBookmark */;
6988391C10518B870022D04C /* PBXTextBookmark */ = 6988391C10518B870022D04C /* PBXTextBookmark */;
6988392510518C7C0022D04C /* PBXTextBookmark */ = 6988392510518C7C0022D04C /* PBXTextBookmark */;
698839531051BA830022D04C /* PBXTextBookmark */ = 698839531051BA830022D04C /* PBXTextBookmark */;
697ED5D51051BD4200E1EF5C = 697ED5D51051BD4200E1EF5C /* PBXTextBookmark */;
698838FF1051826A0022D04C = 698838FF1051826A0022D04C /* PBXTextBookmark */;
698839001051826A0022D04C = 698839001051826A0022D04C /* PBXTextBookmark */;
6988391B10518B870022D04C = 6988391B10518B870022D04C /* PBXTextBookmark */;
6988391C10518B870022D04C = 6988391C10518B870022D04C /* PBXTextBookmark */;
6988392510518C7C0022D04C = 6988392510518C7C0022D04C /* PBXTextBookmark */;
698839531051BA830022D04C = 698839531051BA830022D04C /* PBXTextBookmark */;
};
sourceControlManager = 698838E8105181550022D04C /* Source Control */;
userBuildSettings = {
Expand Down
17 changes: 9 additions & 8 deletions lib/control_freak.rb
Expand Up @@ -17,17 +17,18 @@ def puts_binary(n)
require 'hotcocoa'
include HotCocoa
application do
@tap = EventTap.new
@xkeys = XkeysPedal.new

@xkeys.left_flags = KCGEventFlagMaskAlternate
@xkeys.middle_flags = KCGEventFlagMaskControl
@xkeys.right_flags = KCGEventFlagMaskCommand
@keyboards = DDHidKeyboard.allKeyboards
@keyboards.each do |kb|
kb.track_modifier_keys
end

@tap = EventTap.new
@tap.on_event do |event|
puts_binary(@xkeys.active_flags)
combined_flags = @keyboards.inject(DDHidKeyboard::NO_FLAGS_MASK) do |mask, kb|
mask | kb.flags
end
event.set_flags(event.get_flags | combined_flags)
event
end

end

123 changes: 119 additions & 4 deletions lib/control_freak/ddhid_keyboard.rb
@@ -1,10 +1,117 @@
class DDHidKeyboard
def ddhidKeyboard(keyboard, keyDown: usageId)
key_down_node.publish(usageId)

LeftControl = 0xE0
RightControl = 0xE4
CapsLock = 0x39

LeftShift = 0xE1
RightShift = 0xE5

LeftAlt = 0xE2
RightAlt = 0xE6

LeftCommand = 0xE3
RightCommand = 0xE7


def track_modifier_keys
on_key_down do |keycode|
case keycode
when LeftControl, RightControl, CapsLock
control_on
when LeftShift, RightShift
shift_on
when LeftAlt, RightAlt
alt_on
when LeftCommand, RightCommand
command_on
end
end

on_key_up do |keycode|
case keycode
when LeftControl, RightControl, CapsLock
control_off
when LeftShift, RightShift
shift_off
when LeftAlt, RightAlt
alt_off
when LeftCommand, RightCommand
command_off
end
end

startListening
end

def ddhidKeyboard(keyboard, keyUp: usageId)
key_up_node.publish(usageId)
NO_FLAGS_MASK = 256

def control_on
@control_on = true
end

def control_off
@control_on = false
end

def control_on?
@control_on
end

def control_mask
control_on?? KCGEventFlagMaskControl : NO_FLAGS_MASK
end

def shift_on
@shift_on = true
end

def shift_off
@shift_on = false
end

def shift_on?
@shift_on
end

def shift_mask
shift_on?? KCGEventFlagMaskShift : NO_FLAGS_MASK
end

def alt_on
@alt_on = true
end

def alt_off
@alt_on = false
end

def alt_on?
@alt_on
end

def alt_mask
alt_on?? KCGEventFlagMaskAlternate : NO_FLAGS_MASK
end

def command_on
@command_on = true
end

def command_off
@command_on = false
end

def command_on?
@command_on
end

def command_mask
command_on?? KCGEventFlagMaskCommand : NO_FLAGS_MASK
end

def flags
control_mask | shift_mask | alt_mask | command_mask | NO_FLAGS_MASK
end

def on_key_down(&proc)
Expand All @@ -15,6 +122,14 @@ def on_key_up(&proc)
key_up_node.subscribe(&proc)
end

def ddhidKeyboard(keyboard, keyDown: usageId)
key_down_node.publish(usageId)
end

def ddhidKeyboard(keyboard, keyUp: usageId)
key_up_node.publish(usageId)
end

def key_down_node
@key_down_node ||= ::SubscriptionNode.new
end
Expand Down
4 changes: 4 additions & 0 deletions lib/control_freak/event.rb
Expand Up @@ -26,4 +26,8 @@ def get_user_data
def get_flags
CGEventGetFlags(eventRef)
end

def set_flags(flags)
CGEventSetFlags(eventRef, flags)
end
end
1 change: 0 additions & 1 deletion lib/control_freak/subscription_node.rb
@@ -1,5 +1,4 @@
class SubscriptionNode

attr_reader :subscriptions
def initialize
@subscriptions = []
Expand Down
1 change: 0 additions & 1 deletion lib/control_freak/xkeys_pedal.rb
Expand Up @@ -43,7 +43,6 @@ def middle_flags=(flags)

def right_flags=(flags)
on_right_down do
p "right"
@active_right_flags = flags
end

Expand Down

0 comments on commit d58c552

Please sign in to comment.