Skip to content

Instantly share code, notes, and snippets.

@hyrious
Last active November 2, 2023 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyrious/bb1080b0316dc83ba930ef12c1dd1ca6 to your computer and use it in GitHub Desktop.
Save hyrious/bb1080b0316dc83ba930ef12c1dd1ca6 to your computer and use it in GitHub Desktop.
RGSS mouse wheel event through dll
// gcc -shared -Os -s -o a.dll -m32 mouse-wheel.c
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
HHOOK hook;
DWORD delta;
LRESULT CALLBACK LowLevelMouseProc(_In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM lParam) {
if (wParam == WM_MOUSEWHEEL) {
MSLLHOOKSTRUCT *mouse = (MSLLHOOKSTRUCT *)lParam;
delta += GET_WHEEL_DELTA_WPARAM(mouse->mouseData);
}
return CallNextHookEx(hook, nCode, wParam, lParam);
}
BOOL install() {
hook = SetWindowsHookExA(WH_MOUSE_LL, LowLevelMouseProc, GetModuleHandleA(NULL), 0);
return hook != NULL;
}
BOOL uninstall() {
HHOOK hook_ = hook;
hook = NULL;
return UnhookWindowsHookEx(hook_);
}
DWORD getdelta() {
DWORD delta_ = delta;
delta = 0;
return delta_;
}
#encoding: utf-8
module MouseWheel
def self.install
if Win32API.new('a.dll', 'install', 'v', 'L').call.zero?
puts "MouseWheel.install failed!"
end
end
def self.uninstall
Win32API.new('a.dll', 'uninstall', 'v', 'L').call
end
GetDelta = Win32API.new('a.dll', 'getdelta', 'v', 'i')
def self.update
@delta = GetDelta.call
end
def self.delta
@delta
end
install
end
class << Input
alias _update_mousewheel update
def update
_update_mousewheel
MouseWheel.update
unless MouseWheel.delta.zero?
p MouseWheel.delta
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment