1kc / razer-macos

Color effects manager for Razer devices for macOS. Supports High Sierra (10.13) to Monterey (12.0). Made by the community, based on openrazer.
GNU General Public License v2.0
2.31k stars 252 forks source link

Is there an ability to write python scripts for Razer devices? #70

Open ekng331 opened 3 years ago

ekng331 commented 3 years ago

In the open razer project, there is an ability to program your keyboard using their api via python scripting. Is this feature available in the mac port as well? Here are the provided examples of the scripts: https://github.com/openrazer/openrazer/tree/master/examples

Thanks in advance!

1kc commented 3 years ago

Hi Nanthan, currently you can call the openrazer api in this app with Javascript only. Python scripting is not yet available, but I think it is possible to implement.

Keep in mind the apis in this project are only a subset of openrazer's, as they had to be manually rewriten on Mac.

ekng331 commented 3 years ago

Hi, is there any page where I can find the documentation?

1kc commented 3 years ago

Its not super well documented but I can point you to the right direction. At the bottom of https://github.com/1kc/razer-macos/blob/master/src/driver/addon.cc , you will see a list of functions that you can call from Javascript. These functions will in turn call the C driver functions for you.

For example:

import addon from '../driver'
addon.kbdSetModeStatic(new Uint8Array([0xff,0,0]))} // Set entire keyboard to red

We are not at the stage where we can set colours for individual keys yet. Maybe that is something you could look into porting over if you are interested?

ekng331 commented 3 years ago

Yes, I am interested. Could you please give some explanation on your porting process and also maybe documentation for the original code?

1kc commented 3 years ago

Here is a simple explanation here regarding the porting the driver code, https://github.com/1kc/razer-macos/wiki.

The process goes:

  1. Copying C functions across from https://github.com/openrazer/openrazer/blob/master/driver/razerkbd_driver.c, changing function signatures and variables accordingly. (See existing examples in https://github.com/1kc/razer-macos/blob/master/src/driver/razerkbd_driver.c)
  2. Add C++ wrappers to call these C functions in https://github.com/1kc/razer-macos/blob/master/src/driver/addon.cc, this is a Node Native Addon
  3. Call addon functions in Javascript when user intereacts with the UI (Electron and React, razer-macos/src/main/index.js)
ekng331 commented 3 years ago

How do I set everything up to begin?