FelixKratz / SketchyBar

A highly customizable macOS status bar replacement
https://felixkratz.github.io/SketchyBar/
GNU General Public License v3.0
5.62k stars 86 forks source link

Mouse button code #356

Closed fuyu0425 closed 1 year ago

fuyu0425 commented 1 year ago

Idea: Not just expose "left"/"right"/"other" for a mouse click, but also the button code. It will be useful for a modern mouse with extra buttons (e.g. mine has forward/back buttons).

Which can be get by

uint32_t mouse_button_code = CGEventGetIntegerValueField(context, kCGMouseEventButtonNumber);

I am not proficient in Objective-C and Apple GUI frameworks.

POC: https://github.com/fuyu0425/SketchyBar/commit/9eac182eb0bd6fe9a544a0351527c8879a46f445

My Own Usage for a script to control Music App.

case "$BUTTON" in
 "left")
     PLAYER_STATE=$(osascript -e "tell application \"Music\" to set playerState to (get player state) as text")
     if [[ $PLAYER_STATE == "paused" ]]; then
         osascript -e 'tell application "Music" to play'
     else
         osascript -e 'tell application "Music" to pause'
     fi
     ;;
 "right")
     osascript -e 'tell application "Music" to next track'
     ;;
 "other")
     case "$BUTTON_CODE" in
          "3")
              osascript -e 'tell application "Music" to back track'
              ;;
          "4")
              osascript -e 'tell application "Music" to next track'
              ;;
          *)
              osascript -e 'tell application "Music" to back track'
              ;;
     esac
     ;;
esac
FelixKratz commented 1 year ago

Sounds like a good idea, I think I would want the button code in the $INFO variable https://felixkratz.github.io/SketchyBar/config/events

Feel free to send a pull-request for this feature.