Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
evilC committed Mar 7, 2018
2 parents ad05139 + 32f2526 commit d9583d2
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ AHI uses the Interception driver by Francisco Lopez
5. Run the example script

# Usage
## Initializing the Library
Include the library
```
#Persistent ; (Interception hotkeys do not stop AHK from exiting, so use this)
Expand All @@ -25,13 +26,61 @@ Initialize the library
Interception := AutoHotInterception_Init()
```

## Context mode
Context mode is so named as it takes advantage of AutoHotkey's [Context Sensitive Hotkeys](https://autohotkey.com/docs/Hotkeys.htm#Context).
In AHK, you can wrap your hotkeys in a block like so:
```
#if myVariable == 1
F1::Msgbox You Pressed F1
#if
```
This hotkey would only fire if the `myVariable` was 1.
In context mode, you subscribe to a keyboard, and any time events for that keyboard are just about to happen, then AHI fires your callback, and you set this variable to `1` the hotkey is enabled. After your hotkey fires, AHI fires the callback again and the variable gets set back to `0`.

### Step 1
Register your callback with AHI
```
VID := 0x04F2, PID := 0x0112
Interception.SetContextCallback(VID, PID, Func("SetKb1Context"))
```

### Step 2
Create your callback function, and set the context variable to the value of `state`
```
SetKb1Context(state){
global isKeyboard1Active
Sleep 0 ; We seem to need this for hotstrings to work, not sure why
isKeyboard1Active := state
}
```

### Step 3
Create your hotkeys, wrapped in an `#if` block for that context variable
```
#if isKeyboard1Active
::aaa::JACKPOT
1::
ToolTip % "KEY DOWN EVENT @ " A_TickCount
return
1 up::
ToolTip % "KEY UP EVENT @ " A_TickCount
return
#if
```

## Subscription mode
In Subscription mode, you bypass AHK's hotkey system completely, and Interception notifies you og key events via callbacks.

Subscribe to a key on a specific keyboard
`SubscribeKey(<scanCode>, <block>, <callback>, <VID>, <PID>`
```
VID := 0x04F2, PID := 0x0112
Interception.SubscribeKey(GetKeySC("1"), true, Func("KeyEvent"), VID, PID)
return
```

Callback function is passed state `0 (released) ` or `1` (pressed)
Callback function is passed state `0` (released) or `1` (pressed)
```
KeyEvent(state){
ToolTip % "State: " state
Expand Down

0 comments on commit d9583d2

Please sign in to comment.