View previous topic :: View next topic |
Author |
Message |
catfood Cheater Reputation: 0
Joined: 22 Jun 2015 Posts: 34
|
Posted: Wed Jan 26, 2022 1:04 pm Post subject: fixing my SOMETIMES perfect lua script? |
|
|
hello, i want to be able to use up and down arrow keys on my keyboard to emulate mouse wheel up and down. where pressing up arrow, also acts as a single mouse wheel up, and down arrow for single mouse wheel down.
i however do not want to lose my normal up/down arrow functionality.
what my script does, is by pressing up arrow, does a mouse wheel up, then normal up arrow behavior, and vice versa for down.
it works usually, but here and there it will bug out, and it'll keep pressing me down or up, or double press a direction, or weird up/down loops. and I'm not exactly sure why.
is anyone actually able to tell what might be causing this weird behavior, and how to fix it?
much appreciated, thanks!
[code]
if hk then hk.destroy() hk=nil end
hk=createHotkey(function()
if getForegroundProcess()==getOpenedProcessID() then
--do the mouse wheel up when UP arrow is pressed
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 120, 0)
--lift key just in case idk
keyDown(VK_UP)
-- wait until the up key is pressed
while not isKeyPressed(VK_UP) do
-- do nothing
end
end
end, VK_UP)
hk=createHotkey(function()
if getForegroundProcess()==getOpenedProcessID() then
--do the mouse wheel up when UP arrow is pressed
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -120, 0)
---lift key just in case idk
keyDown(VK_DOWN)
-- wait until the down key is pressed
while not isKeyPressed(VK_DOWN) do
-- do nothing
end
end
end, VK_DOWN)
[/code]
|
|
Back to top |
|
|
Frouk Master Cheater Reputation: 5
Joined: 22 Jun 2021 Posts: 489 Location: mov dword ptr [Ukraine]
|
Posted: Thu Jan 27, 2022 3:26 am Post subject: |
|
|
why
_________________
void(__cdecl *Haxing)(HWND hGameWindow) |
|
Back to top |
|
|
catfood Cheater Reputation: 0
Joined: 22 Jun 2015 Posts: 34
|
Posted: Thu Jan 27, 2022 8:45 am Post subject: |
|
|
[quote="Frouk"]why[/quote]
uhm LOL, why what?
why do I want it fixed? because working > non working.
why do I want this behavior? because you can scroll thru shop windows in my game with a mouse wheel, but laptop touchpad scrolling=/= mouse wheel.
why does the script work the way it does? idk you tell me LOL
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1053 Location: 0x90
|
Posted: Thu Jan 27, 2022 9:50 am Post subject: |
|
|
catfood wrote: |
uhm LOL, why what?
why do I want it fixed? because working > non working.
why do I want this behavior? because you can scroll thru shop windows in my game with a mouse wheel, but laptop touchpad scrolling=/= mouse wheel.
why does the script work the way it does? idk you tell me LOL |
You will need a global mouse hook. Intercept the messages and handle them how you see fit. Because it's pretty low-level stuff, if the solution provided by Dark Byte isn't suffice, I would say that it's perfectly valid to expect that you won't receive a solution to this problem just because of what creating a global mouse hook entails.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Thu Jan 27, 2022 1:26 pm Post subject: |
|
|
I don't look at improperly formatted code in much detail, but you're using the same global variable (hk) for both hotkeys. The first one gets leaked after you assign the second one. i.e. calling destroy will only destroy the second, not the first
That busy wait loop seems bad as well
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
catfood Cheater Reputation: 0
Joined: 22 Jun 2015 Posts: 34
|
Posted: Sat Jan 29, 2022 11:12 am Post subject: |
|
|
[quote="ParkourPenguin"]I don't look at improperly formatted code in much detail, but you're using the same global variable (hk) for both hotkeys. The first one gets leaked after you assign the second one. i.e. calling destroy will only destroy the second, not the first
That busy wait loop seems bad as well[/quote]
I don't know why the forum shows it that way, as I put it in [code] brackets and in the editor it appears correctly with proper tabbing.
anyway, I renamed the second hk functions to see if I could get it to behave any differently, to no effect. =/
is it formatted good for you here?
thanks!
https://pastecode.io/s/15x2054e
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1053 Location: 0x90
|
Posted: Sat Jan 29, 2022 12:31 pm Post subject: |
|
|
Code: |
if hk then hk.destroy(); hk=nil end
|
Missing semi-colon for statements that are on the same line
Code: |
hk = createHotkey(
function()
local fgProc = getForegroundProcess()
local oProc = getOpenedProcessID()
if fgProc == oProc then
if isKeyPressed(VK_UP) then
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 120, 0)
else
return nil
end
end
end, VK_UP
)
|
This checks the foreground process for equality, if so then check if the up arrow is pressed, if the condition
is met then send the mouse_event message.
Code: |
hk2 = createHotkey(
function()
local fgProc = getForegroundProcess()
local oProc = getOpenedProcessID()
if fgProc == oProc then
if isKeyPressed(VK_DOWN) then
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -120, 0)
end
end
end, VK_DOWN
)
|
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Sat Jan 29, 2022 1:24 pm Post subject: |
|
|
There's a checkbox when posting that says "Disable BBCode in this post". You probably have that checked.
You don't need the indentation level on the calls to createHotkey.
The busy while loop is awful and should not exist.
What's with the comment about lifting keys when you call keyDown?
I'm pretty sure CE just uses getAsyncKeyState for hotkeys. Events won't be swallowed by CE, so the normal behaviour of pressed keys (i.e. up/down) shouldn't go away. You should be able to just send the mouse event.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
catfood Cheater Reputation: 0
Joined: 22 Jun 2015 Posts: 34
|
Posted: Sat Jan 29, 2022 2:22 pm Post subject: |
|
|
[quote="LeFiXER"]
le-code
[/quote]
your name is spot on sir!
yes, after a week and a half of trying to fix this myself, it is now working flawlessly! you are the absolute man!!
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1053 Location: 0x90
|
Posted: Sat Jan 29, 2022 2:28 pm Post subject: |
|
|
catfood wrote: |
your name is spot on sir!
yes, after a week and a half of trying to fix this myself, it is now working flawlessly! you are the absolute man!! |
You're welcome. I'm not a professional by any means so I don't know if this is the most efficient way to do it; however, it does work and that said I'm glad to have been a help.
|
|
Back to top |
|
|
|