Skip to content

Commit 080abf8

Browse files
committed
Add hotkey, remove stale code, update Readme
1 parent 3a1780a commit 080abf8

File tree

2 files changed

+83
-42
lines changed

2 files changed

+83
-42
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Using [`obs_sceneitem_set_pos`](https://obsproject.com/docs/reference-scenes.htm
1111
# Usage
1212
- Create a _source_ with desired cursor(e.g Image source or Media source).
1313
- In scripts select _that_ source name.
14+
- To center source (scene item ) go to: Transform > Edit Transform > Positional Alignment > Center
15+
16+
## Advanced usage
1417
- Make a group, add Display Capture, Window Capture.
1518

1619
![img](https://i.imgur.com/CHuLwmp.png)
@@ -34,7 +37,7 @@ Using [`obs_sceneitem_set_pos`](https://obsproject.com/docs/reference-scenes.htm
3437
> Have you ever needed to zoom in on your screen to show some fine detail work,
3538
> or to make your large 4k/ultrawide monitor less daunting?
3639
> Zoom and Follow for OBS Studio does exactly that, zooms in on your mouse and follows it around.
37-
> Configurable and low-impact, you can now do old school Camtasia zoom ins live
40+
> Configurable and low-impact, you can now do old school zoom ins live
3841
3942
See: [Zoom and Follow](https://obsproject.com/forum/resources/zoom-and-follow.1051/) , [source code ](https://github.com/tryptech/obs-zoom-and-follow)
4043

@@ -48,14 +51,25 @@ They all have some level of transparency.
4851
![Imgur](https://i.imgur.com/s3jvZP5.png)
4952

5053
# On the Roadmap
51-
- Visual indicator of mouse up/down state.
5254
- Lua based shaders rendering (on mouse up, down, trail, etc...)
53-
- Custom web page rendering (on mouse up, down, trail, etc...)
55+
- Custom web pages
56+
- Visual indicator of mouse up/down state.
5457

5558
# Acknowledgments
5659
- [`3_4_700`](https://github.com/34700) added offsets functionality for precise custom cursor(like a hand drawn arm holding a pen for artists)
5760
- [`tholman/cursor-effects`](https://github.com/tholman/cursor-effects) - stock cursor trails
5861

5962
# Contribute
63+
You are welcome to contribute. Help is needed.
64+
## Developing
65+
There are roadmap items to choose, you are also free to suggest ideas to add and implement. There are forums and GitHub Issues check them out for suggestions or bug reports.
6066
[Forks](https://help.github.com/articles/fork-a-repo) are a great way to contribute to a repository.
6167
After forking a repository, you can send the original author a [pull request](https://help.github.com/articles/using-pull-requests)
68+
## Marketing
69+
Write articles, reviews or tell your friends about it. The more users we have, the more people we have testing and the better we can become.
70+
## Design
71+
Come up with some new good skins or interactive web skins, and add them.
72+
## Voting
73+
In order to improve this scripting functionality and integrate it into OBS Studio, you are encouraged to vote for this feature:
74+
https://ideas.obsproject.com/posts/71/option-to-highlight-mouse-cursor-and-mouse-clicks
75+
Currently the program lacks a way to get the position of the cursor in the texture and is not available in the OBS Studio shader language.

mouse_skin_obs.py

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import obspython as S # studio
22
from contextlib import contextmanager, ExitStack
3-
from types import SimpleNamespace as dot
4-
from pynput.mouse import Controller # python -m pip install pynput
3+
from itertools import cycle
4+
from pynput.mouse import (
5+
Controller,
6+
) # There mighbt be an import error try run this command: python -m pip install pynput
57

6-
__version__ = "2.1.1"
8+
__version__ = "2.2.0"
79
c = Controller()
810
get_position = lambda: c.position
911

@@ -88,49 +90,52 @@ def send_mouse_move_to_browser(
8890
S.obs_source_send_mouse_move(source, event, False) # do not leave
8991

9092

91-
G = dot()
93+
def apply_scale(x, y, width, height):
94+
width = round(width * x)
95+
height = round(height * y)
96+
return width, height
9297

93-
G.LMB = G.RMB = G.MOUSE_HOOKED = False
94-
# Not yet implemented functionality for mouse up/down events
9598

99+
def lerp(minVal, maxVal, k):
100+
val = minVal + ((maxVal - minVal) * k)
101+
return val
96102

97-
def HTK_1_CB(pressed):
98-
G.LMB = pressed
99103

104+
class Hotkey:
105+
def __init__(self, callback, obs_settings, _id):
106+
self.obs_data = obs_settings
107+
self.hotkey_id = S.OBS_INVALID_HOTKEY_ID
108+
self.hotkey_saved_key = None
109+
self.callback = callback
110+
self._id = _id
100111

101-
def HTK_2_CB(pressed):
102-
G.RMB = pressed
112+
self.load_hotkey()
113+
self.register_hotkey()
114+
self.save_hotkey()
103115

116+
def register_hotkey(self):
117+
description = "Htk " + str(self._id)
118+
self.hotkey_id = S.obs_hotkey_register_frontend(
119+
"htk_id" + str(self._id), description, self.callback
120+
)
121+
S.obs_hotkey_load(self.hotkey_id, self.hotkey_saved_key)
104122

105-
def hook_mouse_buttons():
106-
if G.MOUSE_HOOKED:
107-
raise RuntimeError("already hooked mouse")
108-
key_1 = '{"htk_1_mouse": [ { "key": "OBS_KEY_MOUSE1" } ], '
109-
key_2 = '"htk_2_mouse": [ { "key": "OBS_KEY_MOUSE2" } ]}'
110-
json_s = key_1 + key_2
111-
default_hotkeys = [
112-
dot(id="htk_1_mouse", des="LMB state", callback=HTK_1_CB),
113-
dot(id="htk_2_mouse", des="RMB state", callback=HTK_2_CB),
114-
]
115-
settings = S.obs_data_create_from_json(json_s)
116-
for k in default_hotkeys:
117-
a = S.obs_data_get_array(settings, k.id)
118-
h = S.obs_hotkey_register_frontend(k.id, k.des, k.callback)
119-
S.obs_hotkey_load(h, a)
120-
S.obs_data_array_release(a)
121-
S.obs_data_release(settings)
122-
G.MOUSE_HOOKED = True
123+
def load_hotkey(self):
124+
self.hotkey_saved_key = S.obs_data_get_array(
125+
self.obs_data, "htk_id" + str(self._id)
126+
)
127+
S.obs_data_array_release(self.hotkey_saved_key)
123128

129+
def save_hotkey(self):
130+
self.hotkey_saved_key = S.obs_hotkey_save(self.hotkey_id)
131+
S.obs_data_set_array(
132+
self.obs_data, "htk_id" + str(self._id), self.hotkey_saved_key
133+
)
134+
S.obs_data_array_release(self.hotkey_saved_key)
124135

125-
def apply_scale(x, y, width, height):
126-
width = round(width * x)
127-
height = round(height * y)
128-
return width, height
129136

130-
131-
def lerp(minVal, maxVal, k):
132-
val = minVal + ((maxVal - minVal) * k)
133-
return val
137+
class HotkeyDataHolder:
138+
htk_copy = None # this attribute will hold instance of Hotkey
134139

135140

136141
class CursorAsSource:
@@ -228,8 +233,9 @@ def ticker(self): # it is not a thread because obs might not close properly
228233
S.remove_current_callback()
229234

230235

236+
HOTKEY_DATA_HOLDER = HotkeyDataHolder()
231237
PY_CURSOR = CursorAsSource()
232-
hook_mouse_buttons()
238+
HOTKEY_TOGGLE_ITERATOR = cycle([True, False])
233239
############### ############### ###############
234240

235241

@@ -245,6 +251,25 @@ def start_pressed(props, prop):
245251
PY_CURSOR.flag = False # to keep only one timer callback
246252

247253

254+
def callback_on_off(pressed):
255+
if pressed:
256+
a = b = "undefined"
257+
if next(HOTKEY_TOGGLE_ITERATOR):
258+
start_pressed(a, b)
259+
else:
260+
stop_pressed(a, b)
261+
262+
263+
def script_load(settings):
264+
HOTKEY_DATA_HOLDER.htk_copy = Hotkey(
265+
callback_on_off, settings, "On/Off cursor skin"
266+
)
267+
268+
269+
def script_save(settings):
270+
HOTKEY_DATA_HOLDER.htk_copy.save_hotkey()
271+
272+
248273
def react_property(props, prop, settings):
249274
p = S.obs_properties_get(props, "target")
250275
p2 = S.obs_properties_get(props, "browser")
@@ -347,9 +372,11 @@ def script_properties():
347372
<h3 style="color:orange">Authors</h3>
348373
<a href="https://github.com/upgradeQ"> upgradeQ </a> <br>
349374
<a href="https://github.com/3_4_700"> 34700 </a>
350-
""".format(**locals())
375+
""".format(
376+
**locals()
377+
)
351378

352379

353380
def script_description():
354-
print(description,"Released under MIT license")
381+
print(description, "Released under MIT license")
355382
return description

0 commit comments

Comments
 (0)