#hs.razer

Razer device support.

This extension supports the following Razer keypad devices:

  • Razer Nostromo
  • Razer Orbweaver
  • Razer Orbweaver Chroma
  • Razer Tartarus
  • Razer Tartarus Chroma
  • Razer Tartarus Pro
  • Razer Tartarus V2

It allows you to trigger callbacks when you press buttons and use the scroll wheel, as well as allowing you to change the LED backlights on the buttons and scroll wheel, and control the three status lights.

By default, the Razer keypads triggers regular keyboard commands (i.e. pressing the "01" key will type "1"). However, you can use the :defaultKeyboardLayout(false) method to prevent this. This works by remapping the default shortcut keys to "dummy" keys, so that they don't trigger regular keypresses in macOS.

Like the hs.streamdeck extension, this extension has been designed to be modular, so it's possible for others to develop support for additional Razer devices later down the line, if there's interest.

This extension was thrown together by Chris Hocking for CommandPost.

This extension is based off the hs.streamdeck extension by Chris Jones.

Special thanks to the authors of these awesome documents & resources:


#API Overview

Functions - API calls offered directly by the extension

Methods - API calls which can only be made on an object returned by a constructor


#API Documentation

#Functions

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.razer.discoveryCallback(fn) -> none | | Type | Function | | Description | Sets/clears a callback for reacting to device discovery events | | Parameters |

  • fn - A function that will be called when a Razer device is connected or disconnected. It should take the following arguments: A boolean, true if a device was connected, false if a device was disconnected An hs.razer object, being the device that was connected/disconnected
| | Returns |
  • None
| | Notes | None | | Examples | None | | Source | extensions/razer/librazer.m line 48 |


Signaturehs.razer.getDevice(num) -> razerObject | nil
TypeFunction
DescriptionGets an hs.razer object for the specified device
Parameters
  • num - A number that should be within the bounds of the number of connected devices
Returns
  • An hs.razer object or nil if something goes wrong
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 92

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.razer.init(fn) | | Type | Function | | Description | Initialises the Razer driver and sets a discovery callback. | | Parameters |

  • fn - A function that will be called when a Razer device is connected or disconnected. It should take the following arguments: A boolean, true if a device was connected, false if a device was disconnected An hs.razer object, being the device that was connected/disconnected
| | Returns |
  • None
| | Notes |
  • This function must be called before any other parts of this module are used
| | Examples | None | | Source | extensions/razer/librazer.m line 23 |


Signaturehs.razer.numDevices() -> number
TypeFunction
DescriptionGets the number of Razer devices connected
Parameters
  • None
Returns
  • A number containing the number of Razer devices attached to the system
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 75

Signaturehs.razer.unitTests() -> none
TypeFunction
DescriptionRuns some basic unit tests when a Razer Tartarus V2 is connected.
Parameters
  • None
Returns
  • None
Notes
  • Because hs.razer relies on a physical device to
  • be connected for testing, this method exists so that
  • Hammerspoon developers can test the extension outside
  • of the usual GitHub tests. It can also be used for
  • user troubleshooting.
  • This feature currently only works on the Razer Tartarus V2.
ExamplesNone
Sourceextensions/razer/razer.lua line 87

#Methods

Signaturehs.razer:backlightsBreathing([color], [secondaryColor]) -> razerObject, boolean, string | nil
TypeMethod
DescriptionChanges the keyboard backlights to the breath mode.
Parameters
  • [color] - An optional hs.drawing.color value
  • [secondaryColor] - An optional secondary hs.drawing.color
Returns
  • The hs.razer object.
  • true if successful otherwise false
  • A plain text error message if not successful.
Notes
  • If neither color nor secondaryColor is provided, then random colors will be used.
ExamplesNone
Sourceextensions/razer/librazer.m line 844

Signaturehs.razer:backlightsCustom(colors) -> razerObject, boolean, string | nil
TypeMethod
DescriptionChanges the keyboard backlights to custom colours.
Parameters
  • colors - A table of hs.drawing.color objects for each individual button on your device (i.e. if there's 20 buttons, you should have twenty colors in the table).
Returns
  • The hs.razer object.
  • true if successful otherwise false
  • A plain text error message if not successful.
Notes
  • The order is top to bottom, left to right. You can use nil for any buttons you don't want to light up.
  • Example usage: lua</li><li> hs.razer.new(0):backlightsCustom({hs.drawing.color.red, nil, hs.drawing.color.green, hs.drawing.color.blue})</li><li>
ExamplesNone
Sourceextensions/razer/librazer.m line 891

Signaturehs.razer:backlightsMode(mode) -> razerObject, boolean, string | nil
TypeMethod
DescriptionChanges the keyboard backlights mode.
Parameters
  • mode - "static", "flashing", "fading"
Returns
  • The hs.razer object.
  • true if successful otherwise false.
  • A plain text error message if not successful.
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 555

Signaturehs.razer:backlightsOff() -> razerObject, boolean, string | nil
TypeMethod
DescriptionTurns all the keyboard backlights off.
Parameters
  • None
Returns
  • The hs.razer object.
  • true if successful otherwise false.
  • A plain text error message if not successful.
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 630

Signaturehs.razer:backlightsReactive(speed, color) -> razerObject, boolean, string | nil
TypeMethod
DescriptionChanges the keyboard backlights to the reactive mode.
Parameters
  • speed - A number between 1 (fast) and 4 (slow)
  • color - A hs.drawing.color object
Returns
  • The hs.razer object.
  • true if successful otherwise false
  • A plain text error message if not successful.
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 744

Signaturehs.razer:backlightsSpectrum() -> razerObject, boolean, string | nil
TypeMethod
DescriptionChanges the keyboard backlights to the spectrum mode.
Parameters
  • None
Returns
  • The hs.razer object.
  • true if successful otherwise false
  • A plain text error message if not successful.
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 712

Signaturehs.razer:backlightsStarlight(speed, [color], [secondaryColor]) -> razerObject, boolean, string | nil
TypeMethod
DescriptionChanges the keyboard backlights to the Starlight mode.
Parameters
  • speed - A number between 1 (fast) and 3 (slow)
  • [color] - An optional hs.drawing.color value
  • [secondaryColor] - An optional secondary hs.drawing.color
Returns
  • The hs.razer object.
  • true if successful otherwise false
  • A plain text error message if not successful.
Notes
  • If neither color nor secondaryColor is provided, then random colors will be used.
ExamplesNone
Sourceextensions/razer/librazer.m line 787

Signaturehs.razer:backlightsStatic(color) -> razerObject, boolean, string | nil
TypeMethod
DescriptionChanges the keyboard backlights to a single static color.
Parameters
  • color - A hs.drawing.color object.
Returns
  • The hs.razer object.
  • true if successful otherwise false.
  • A plain text error message if not successful.
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 596

Signaturehs.razer:backlightsWave(speed, direction) -> razerObject, boolean, string | nil
TypeMethod
DescriptionChanges the keyboard backlights to the wave mode.
Parameters
  • speed - A number between 1 (fast) and 255 (slow)
  • direction - "left" or "right" as a string
Returns
  • The hs.razer object.
  • true if successful otherwise false
  • A plain text error message if not successful.
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 662

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.razer:blueStatusLight(value) -> razerObject, boolean | nil, string | nil | | Type | Method | | Description | Gets or sets the blue status light. | | Parameters |

  • value - true for on, false for off</li></ul> | | **Returns** | <ul><li>The hs.razer object.</li><li>truefor on,false for off, or nil if something has gone wrong
  • A plain text error message if not successful.
| | Notes | None | | Examples | None | | Source | extensions/razer/librazer.m line 443 |


Signaturehs.razer:brightness(value) -> razerObject, number | nil, string | nil
TypeMethod
DescriptionGets or sets the brightness of a Razer keyboard.
Parameters
  • value - The brightness value - a number between 0 (off) and 100 (brightest).
Returns
  • The hs.razer object.
  • The brightness as a number or nil if something goes wrong.
  • A plain text error message if not successful.
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 221

Signaturehs.razer:callback(callbackFn) -> razerObject
TypeMethod
DescriptionSets or removes a callback function for the hs.razer object.
Parameters
  • callbackFn - a function to set as the callback for this hs.razer object. If the value provided is nil, any currently existing callback function is removed.
Returns
  • The hs.razer object
Notes
  • The callback function should expect 4 arguments and should not return anything:
  • razerObject - The serial port object that triggered the callback.
  • buttonName - The name of the button as a string.
  • buttonAction - A string containing "pressed", "released", "up" or "down".
ExamplesNone
Sourceextensions/razer/librazer.m line 147

Signaturehs.razer:defaultKeyboardLayout(enabled) -> boolean
TypeMethod
DescriptionAllows you to remap the default Keyboard Layout on a Razer device so that the buttons no longer trigger their factory default actions, or restore the default keyboard layout.
Parameters
  • enabled - If true the Razer default will use its default keyboard layout.
Returns
  • The hs.razer object.
  • true if successful otherwise false
NotesNone
ExamplesNone
Sourceextensions/razer/razer.lua line 52

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.razer:greenStatusLight(value) -> razerObject, boolean | nil, string | nil | | Type | Method | | Description | Gets or sets the green status light. | | Parameters |

  • value - true for on, false for off</li></ul> | | **Returns** | <ul><li>The hs.razer object.</li><li>truefor on,false for off, or nil if something has gone wrong
  • A plain text error message if not successful.
| | Notes | None | | Examples | None | | Source | extensions/razer/librazer.m line 388 |


Signaturehs.razer:name() -> string
TypeMethod
DescriptionReturns the human readable device name of the Razer device.
Parameters
  • None
Returns
  • The device name as a string.
NotesNone
ExamplesNone
Sourceextensions/razer/librazer.m line 125

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.razer:orangeStatusLight(value) -> razerObject, boolean | nil, string | nil | | Type | Method | | Description | Gets or sets the orange status light. | | Parameters |

  • value - true for on, false for off</li></ul> | | **Returns** | <ul><li>The hs.razer object.</li><li>truefor on,false for off, or nil if something has gone wrong
  • A plain text error message if not successful.
| | Notes | None | | Examples | None | | Source | extensions/razer/librazer.m line 278 |


| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.razer:redStatusLight(value) -> razerObject, boolean | nil, string | nil | | Type | Method | | Description | Gets or sets the red status light. | | Parameters |

  • value - true for on, false for off</li></ul> | | **Returns** | <ul><li>The hs.razer object.</li><li>truefor on,false for off, or nil if something has gone wrong
  • A plain text error message if not successful.
| | Notes | None | | Examples | None | | Source | extensions/razer/librazer.m line 498 |


| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.razer:yellowStatusLight(value) -> razerObject, boolean | nil, string | nil | | Type | Method | | Description | Gets or sets the orange status light. | | Parameters |

  • value - true for on, false for off</li></ul> | | **Returns** | <ul><li>The hs.razer object.</li><li>truefor on,false for off, or nil if something has gone wrong
  • A plain text error message if not successful.
| | Notes | None | | Examples | None | | Source | extensions/razer/librazer.m line 333 |