add mouse event, fix project name, add dll behaviour
Some checks failed
Upload release / build (push) Has been cancelled

This commit is contained in:
Mylloon 2024-10-07 21:53:11 +02:00
parent 5bd7ff14e2
commit 39dadd8cfa
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 37 additions and 11 deletions

View file

@ -16,10 +16,12 @@ jobs:
apt-get install -y mingw-w64 zip
- name: Build
run: make
run: |
make &&
mv LICENSE LICENSE-AORBR
- name: Create ZIP file
run: zip -r auto-obs-rp-restart.zip LICENSE AutoOBSRPRestart.lua monitor.dll
run: zip -r auto-obs-rb-restart.zip LICENSE-AORBR AutoOBSRBRestart.lua monitor.dll
- name: Create release
uses: akkuman/gitea-release-action@v1
@ -27,4 +29,4 @@ jobs:
token: ${{ secrets.TOKEN }}
name: Latest version
tag_name: latest
files: auto-obs-rp-restart.zip
files: auto-obs-rb-restart.zip

View file

@ -15,7 +15,7 @@ function script_load()
ffi.cdef[[
void start_hook(void);
void stop_hook(void);
int last_time_input_received(void);
time_t last_time_input_received(void);
]]
monitor = ffi.load(script_path() .. "monitor.dll")

View file

@ -1,5 +1,10 @@
# Auto OBS RP Restart [![status-badge](https://git.mylloon.fr/Anri/auto-obs-rp-restart/badges/workflows/release.yml/badge.svg)](https://git.mylloon.fr/Anri/auto-obs-rp-restart/actions?workflow=release.yml)
# Automatic OBS ReplayBuffer Restart [![status-badge](https://git.mylloon.fr/Anri/auto-obs-rb-restart/badges/workflows/release.yml/badge.svg)](https://git.mylloon.fr/Anri/auto-obs-rb-restart/actions?workflow=release.yml)
Automatically restarts the replay buffer when IDLE
- [Download the latest release here](https://git.mylloon.fr/Anri/auto-obs-rp-restart/releases/tag/latest)
- [Download the latest release here](https://git.mylloon.fr/Anri/auto-obs-rb-restart/releases/tag/latest)
The script wait 2 hours before looking for any input for the last 2 minutes.
If there is none, then it restarts the replay buffer.
Else it waits for the next 2 minutes, etc.
Once restarted, the script wait 2 other hours.

View file

@ -1,26 +1,45 @@
#include <stdatomic.h>
#include <time.h>
#include <windows.h>
static DWORD last_input_time = 0; // Store the last input time in milliseconds
static atomic_llong last_input_time = 0;
HHOOK hKeyboardHook;
HHOOK hMouseHook;
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION) {
last_input_time = time(NULL);
atomic_store(&last_input_time, time(NULL));
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION) {
atomic_store(&last_input_time, time(NULL));
}
return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
}
__declspec(dllexport) void start_hook(void) {
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0);
hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0);
}
__declspec(dllexport) void stop_hook(void) {
UnhookWindowsHookEx(hKeyboardHook);
if (hKeyboardHook) {
UnhookWindowsHookEx(hKeyboardHook);
hKeyboardHook = NULL;
}
if (hMouseHook) {
UnhookWindowsHookEx(hMouseHook);
hMouseHook = NULL;
}
}
__declspec(dllexport) int last_time_input_received(void) {
return last_input_time;
__declspec(dllexport) time_t last_time_input_received(void) {
return atomic_load(&last_input_time);
}