Skip to content

Commit

Permalink
adapted to mouse side buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
BHznJNs committed Dec 13, 2024
1 parent 296c854 commit 57469b2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
6 changes: 4 additions & 2 deletions docs/shortcuts_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ The shortcuts following are available after connection:
| Shortcut | Description |
| --- | --- |
| `<Ctrl>+<Alt>+s` | Toggle the control between your computer and your Android device |
| `<Ctrl>+<Alt>+q` | Quit the program |
| `F1` | Multi-task switching |
| `<Ctrl>+<Alt>+q` | Quit the Program |
| `F1` | Multi-task Switching |
| `F2` | Return to Home |
| `F3` | Back |
| `F4` | Previous Media |
Expand All @@ -18,6 +18,8 @@ The shortcuts following are available after connection:
| `F10` | Brightness Up |
| `F11` | Screen Sleep |
| `F12` | Wake Up |
| Mouse side button `X1` | Back |
| Mouse side button `X2` | Open Notification |

The shortcuts following are available after connection and not sharing:

Expand Down
2 changes: 2 additions & 0 deletions docs/shortcuts_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
| `F10` | 提升亮度 |
| `F11` | 熄屏 |
| `F12` | 亮屏 |
| 鼠标侧键 `X1` | 返回 |
| 鼠标侧键 `X2` | 打开通知栏 |

下面的快捷键在你连接设备完成后且没有共享输入时可用:

Expand Down
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,31 @@ <h2>Shortcuts</h2>
</div>
</td>
</tr>
<tr>
<td>Mouse side button <kbd>X1</kbd></td>
<td>Back</td>
<td>
<div class="icon-container">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-arrow-return-left" viewBox="0 0 16 16">
<path fill-rule="evenodd"
d="M14.5 1.5a.5.5 0 0 1 .5.5v4.8a2.5 2.5 0 0 1-2.5 2.5H2.707l3.347 3.346a.5.5 0 0 1-.708.708l-4.2-4.2a.5.5 0 0 1 0-.708l4-4a.5.5 0 1 1 .708.708L2.707 8.3H12.5A1.5 1.5 0 0 0 14 6.8V2a.5.5 0 0 1 .5-.5z" />
</svg>
</div>
</td>
</tr>
<tr>
<td>Mouse side button <kbd>X2</kbd></td>
<td>Open Notification</td>
<td>
<div class="icon-container">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#000">
<path
d="M160-200v-80h80v-280q0-83 50-147.5T420-792v-28q0-25 17.5-42.5T480-880q25 0 42.5 17.5T540-820v28q80 20 130 84.5T720-560v280h80v80H160Zm320-300Zm0 420q-33 0-56.5-23.5T400-160h160q0 33-23.5 56.5T480-80ZM320-280h320v-280q0-66-47-113t-113-47q-66 0-113 47t-47 113v280Z" />
</svg>
</div>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
16 changes: 11 additions & 5 deletions input/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,26 @@ def mouse_click_callback(_cur_x: int, _cur_y: int, button: mouse.Button, pressed
return None

hid_button = HID_MouseButton.MOUSE_BUTTON_NONE
keyevent_action = AKeyEventAction.AKEY_EVENT_ACTION_DOWN if pressed else AKeyEventAction.AKEY_EVENT_ACTION_UP
match button:
case mouse.Button.left:
hid_button = HID_MouseButton.MOUSE_BUTTON_LEFT
case mouse.Button.right:
hid_button = HID_MouseButton.MOUSE_BUTTON_RIGHT
case mouse.Button.middle:
hid_button = HID_MouseButton.MOUSE_BUTTON_MIDDLE
if pressed:
mouse_button_state.mouse_down(hid_button)
else:
mouse_button_state.mouse_up(hid_button)
case mouse.Button.x1:
keycode = InjectKeyCode(AKeyCode.AKEYCODE_BACK, keyevent_action)
return send_data(keycode.serialize())
case mouse.Button.x2:
keycode = InjectKeyCode(AKeyCode.AKEYCODE_NOTIFICATION, keyevent_action)
return send_data(keycode.serialize())

if pressed: mouse_button_state.mouse_down(hid_button)
else: mouse_button_state.mouse_up(hid_button)
mouse_move_event = MouseClickEvent(mouse_button_state)
return send_data(mouse_move_event.serialize())

def mouse_scroll_callback(_cur_x: int, _cur_y: int, _dx: int, dy: int, is_redirecting: bool) -> CallbackResult:
if not is_redirecting or get_config().share_keyboard_only:
return None
Expand Down

0 comments on commit 57469b2

Please sign in to comment.