Ghub lua unbind "back" to mouse button #4 - lua

I'm currently trying to use Ghub's lua scripting function (on Mac) so that when I hold down mouse button 4/5, I can repeatedly scroll up/down, until mouse button 4/5 is released. The following is a code snippet of what I have
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" then
if arg == 5 then
repeat
MoveMouseWheel(-60)
Sleep(50)
OutputLogMessage(tostring(IsMouseButtonPressed(arg)))
until not IsMouseButtonPressed(arg)
elseif arg == 4 then
repeat
MoveMouseWheel(60)
Sleep(50)
OutputLogMessage(tostring(IsMouseButtonPressed(arg)))
until not IsMouseButtonPressed(arg)
end
end
end
The code indeed does what it's supposed to do, except for the fact that when I release mouse button 4/5, it also simulates the default back/forward behavior (for example, on Chrome). I originally thought my script would supersede the default behavior, but it seems that's not true.
Question. How would one unbind the default behavior? (And does this always happen with lua scripting?)

Related

Do not record key presses when pressed in GHUB/Logitech Gaming Software

I made this script with LUA in GHUB:
function OnEvent(event, arg)
if IsMouseButtonPressed(5) then
PressKey("r")
Sleep(math.random(30, 100))
ReleaseKey("r")
Sleep(math.random(30, 100))
end
end
But I don't want mouse button 5 to be detected.
In fact, if I try to press it, it will record the pressure of key 5 and then it starts the script.
Is there a way to press the key without it being detected?
You can open this image to understand better
I thought that to do this I could create a macro instead of a script but I need a random delay. How can I solve?
I'm not sure I have understood you correctly, but this is the obvious steps:
Check event and arg in the script instead of IsMouseButtonPressed:
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
PressKey("r")
Sleep(math.random(30, 100))
ReleaseKey("r")
end
end
If you want to disable Mouse Button 5 be "detected" when you press it:
Go to GHUB (mouse device, "Assignments" screen).
Unassign standard command "Forward" from physical MB#5 (click and select DISABLE from the drop-down menu).
Disabled MB#5 will look like a white circle with black inside.

Players spamming jump does not trigger Touched" event

So I'm making a sort of spleef type game where players jump around as blocks disappear beneath them. However, if you just hold down the space bar, Roblox doesn't seem to register the "Touched" event. Can anyone help?
Here is my script for each of the disappearing platforms:
local platform = script.Parent
local function fade()
print("Touched!")
platform.Transparency = 1
platform.CanCollide = false
end
platform.OnTouched:Connect(fade)
A BasePart doesn't have an event named "OnTouched", but I think you are referring to "Touched" event of BasePart.
You can change the platform.OnTouched:Connect(fade) to platform.Touched:Connect(fade)
https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched
With new r15 anthro models, sometimes the touch won't register as the hitbox fails to register a touch.
What I did a long ago was to create an invisible box with no collision that is thin above the part that you would like to touch, then check the .Touched event in the invisible box instead the one you are checking right now.

How do make a random.math int populate with every iteration of a function?

I'm creating my first ever coding project, a macro for my Logitech mouse using Lua, and I have a repeating function (autoclick) that I would like to generate a random delay between clicks.
I want it to be:
toggle-able with "scroll lock"
adjustable delay on the fly
to simply click and hold left-click to use
My code is as follows:
--Button used to turn rapid fire on/off
rfLock="scrolllock"
--Rapid fire values used in randomization/realism, in ms (milleseconds).
rfLo=45
rfHi=75
EnablePrimaryMouseButtonEvents(true);
function RapidFire()
if (rfLock==true) then
if (IsMouseButtonPressed(1)==true)then
repeat
ReleaseMouseButton(1)
sleep (math.random(rfLo,rfHi))
PressMouseButton(1)
until not IsMouseButtonPressed(1)
function OnEvent(event, arg)
if IsKeyLockOn(rfLock)then
rFire=true
else
rFire=false
end
end
Is there another way I have to approach this? It currently does not do anything. I'm still trying to figure it out obviously, just thought I could get the knowledge from you guys here. Thanks in advance.
I assume you are using GHUB (but the same could be done in LGS).
Step 0.
You are about to modify the behavior of Left Mouse Button.
This is a potentially dangerous operation: you can do nothing on your computer without LMB.
So you must create a "spare LMB".
For example, if you don't use Mouse Button 8, you can make it acting like a clone on LMB.
Go to GHUB (mouse device, "Assignments" screen, SYSTEM tab).
Bind "Primary click" to your physical MB#8.
Now, if something goes wrong and your LMB stops working, you can press MB#8 instead of LMB.
It might happen that you don't want to expend a mouse button for "spare LMB" because all the mouse buttons are in use for something important.
If you have a Logitech keyboard you can use one of its G-buttons as "spare LMB" (keyboard device, "Assignments" screen, SYSTEM tab).
Step 1.
Do you use Mouse Button 4 ("back") in the game?
If YES (some action is assigned to MB#4 in the game), proceed to "Step 2".
If NO (the game ignores MB#4 press), skip "Step 2" and proceed to "Step 3".
Step 2.
You have to remap game action from MB#4 to some other key.
Do the following:
choose keyboard button you don't currently use in the game
(let's assume the F12 key is not currently used)
go to GHUB (mouse device, "Assignments" screen, KEYS tab);
bind F12 to your physical MB#4
go to game options;
assign the game action to F12 instead of MB#4
Now when you press physical MB#4, the game receives F12 and activates the game action.
Skip "Step 3" and proceed to "Step 4".
Step 3.
Go to GHUB (mouse device, "Assignments" screen).
Unbind "Back" from physical MB#4 (click and select DISABLE from the drop-down menu).
Disabled MB#4 will look like a white circle with black inside.
Step 4.
Set the script (see below).
Step 5.
Go to GHUB (mouse device, "Assignments" screen, SYSTEM tab).
Bind "Back" to your physical LMB.
You will see a warning about a potentially dangerous operation.
Allow this operation because you have the "spare LMB".
--Button used to turn rapid fire on/off
local rfLock = "scrolllock"
--Rapid fire values used in randomization/realism, in ms (milleseconds).
local rfLo = 45
local rfHi = 75
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
PressMouseButton(1)
if IsKeyLockOn(rfLock) then
repeat
Sleep(math.random(rfLo,rfHi))
if not IsMouseButtonPressed(4) then break end
ReleaseMouseButton(1)
Sleep(math.random(rfLo,rfHi))
PressMouseButton(1)
until not IsMouseButtonPressed(4) -- 4 = "Back"
end
elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
ReleaseMouseButton(1)
end
end

Detecting event.button of MouseEvent for non-standard buttons

I allow users to record mouse combintations for my add-on. However I'm curious what happens when a 4th or 5th button is pressed? Will event.button be 3 and 4? I'm hoping it is.
function detect(e) {
console.log('button pressed = ', e.button); //e.button is 0 for left, 1 for right, 2 for middle/wheel button
}
document.addEventListener('click', detect, false);
if e.button is not 3 or 4 is there a way to get it to be?
In theory, you could get this from MouseEvent.buttons. In practice, however... Well, see the Gecko Notes section of the docs for yourself.

iPad CSS3 webkitTransform and touch events - a slight unexplained stutter

This is pertaining to an image gallery, so as you "swipe", images are loaded and unloaded off of the screen, but the center image always appears smoothly.
It is code derived from the swipeview library described here: http://cubiq.org/swipeview
The problem is that, there is a 100-200ms delay which occurs between when the javascript sets the webkitTransform in the touch end event, and when the element actually starts animating on the screen.
This problematic delay, only happens intermittently; it seems that it starts happening consistently after about 15-20 slides have been unloaded/loaded.
In the touch move event there is code like this:
element.style.webkitTransitionDuration = 0
element.style.webkitTransform = "translate3d( etc. ) "
And this functions very fast, such that if you move your finger around on the ipad, the element follows your finger precisely and "instantly".
And in the touch end event there is code like this:
element.style.webkitTransitionDuration = '<some_number>ms';
element.style.webkitTransform = "translate3d( etc. ) "
And the touch end event is where the problem is. The touch End event itself fires the instant the finger is removed from the ipad, however, when the problem is happening, the css update doesnt trigger an actual animation on screen until after the problematic delay mentioned above.
This was a tricky one. I finally found the culprit. In my touchend event listener, I was calling a function that added classes to DOM elements. This caused Safari to take a moment to rewire textures to the GPU, resulting in the stutter. Removing those direct className updates made it all buttery smooth again (and I'm still using requestAnimationFrame and not CSS transitions).
I moved my className changes to a separate event that fired from touchend instead and it didn't cause any performance issues. So, if you must set classes, just don't do it directly in the touchend callback. Trigger another event instead or set the classes in requestAnimationFrame.

Resources