Hiding Posted July 3 Share Posted July 3 Hi, When I use showCursor(true) to open a panel, the cursor appears in the center of the screen for a short moment, then instantly jumps to where it was before I closed the panel. I tried saving the last position using getCursorPosition() and restoring it with setCursorPosition(), but it doesn't help. Any idea how to prevent the cursor jumping from the center? Link to comment
CastiaL Posted July 4 Share Posted July 4 cursorX, cursorY = getCursorPosition() -- showCursor(false) <-- Use Before Then ... -- showCursor(true) <-- Use After Then screenX, screenY = guiGetScreenSize() setCursorPosition(cursorX*screenX, cursorY*screenY) 1 Link to comment
Hiding Posted July 4 Author Share Posted July 4 2 hours ago, CastiaL said: cursorX, cursorY = getCursorPosition() -- showCursor(false) <-- Use Before Then ... -- showCursor(true) <-- Use After Then screenX, screenY = guiGetScreenSize() setCursorPosition(cursorX*screenX, cursorY*screenY) As I mentioned, I already tried getCursorPosition and setCursorPosition, but it doesn't work — the cursor still starts from the center of the screen.. local function togglePanel() toggle = not toggle if toggle then if savedCursorX and savedCursorY then local screenX, screenY = guiGetScreenSize() setCursorPosition(savedCursorX * screenX, savedCursorY * screenY) end showCursor(true) else savedCursorX, savedCursorY = getCursorPosition() showCursor(false) end end bindKey("k", "down", togglePanel) Doesnt work this way Link to comment
efex Posted July 4 Share Posted July 4 local toggle = false local savedCursorX, savedCursorY local function restoreCursorPos() if savedCursorX and savedCursorY then local screenX, screenY = guiGetScreenSize() setCursorPosition(savedCursorX * screenX, savedCursorY * screenY) end end local function togglePanel() toggle = not toggle if toggle then showCursor(true) for i = 1, 5 do setTimer(restoreCursorPos, i * 50, 1) end else savedCursorX, savedCursorY = getCursorPosition() showCursor(false) end end bindKey("k", "down", togglePanel) Can you just try this? ı added a timer for it. 1 Link to comment
Hiding Posted July 4 Author Share Posted July 4 14 minutes ago, efex said: local toggle = false local savedCursorX, savedCursorY local function restoreCursorPos() if savedCursorX and savedCursorY then local screenX, screenY = guiGetScreenSize() setCursorPosition(savedCursorX * screenX, savedCursorY * screenY) end end local function togglePanel() toggle = not toggle if toggle then showCursor(true) for i = 1, 5 do setTimer(restoreCursorPos, i * 50, 1) end else savedCursorX, savedCursorY = getCursorPosition() showCursor(false) end end bindKey("k", "down", togglePanel) Can you just try this? ı added a timer for it. Thank you, but same :~.. xd doesnt help Link to comment
efex Posted July 4 Share Posted July 4 Is there any error on debug or F8? I dont understand why its not working 1 Link to comment
Hiding Posted July 4 Author Share Posted July 4 39 minutes ago, efex said: Is there any error on debug or F8? I dont understand why its not working No any errors.. Link to comment
efex Posted July 4 Share Posted July 4 (edited) I've run out of suggestions unfortunately, if i have smth i will come back Edited July 4 by efex 1 Link to comment
Shady1 Posted July 4 Share Posted July 4 There are two kinds of methods, one with setTimer and the other with the alternative onClientRender setTimer : The cursor always appears in the center for one frame after showCursor(true). function openPanel() showCursor(true) -- Save the last cursor position (values between 0 and 1) local x, y = getCursorPosition() -- Get the screen resolution local sx, sy = guiGetScreenSize() -- After 50ms, set the cursor back to its previous position setTimer(function() setCursorPosition(x * sx, y * sy) end, 50, 1) end onClientRender: Use a timer or onClientRender to set the position after showing the cursor. function panelAc() showCursor(true) local x, y = getCursorPosition() local sx, sy = guiGetScreenSize() local function imlecDuzelt() setCursorPosition(x * sx, y * sy) removeEventHandler("onClientRender", root, imlecDuzelt) end addEventHandler("onClientRender", root, imlecDuzelt) end your fixed code : local toggle = false local savedCursorX, savedCursorY local function togglePanel() toggle = not toggle if toggle then showCursor(true) if savedCursorX and savedCursorY then local screenX, screenY = guiGetScreenSize() -- Wait one frame before setting the cursor position setTimer(function() setCursorPosition(savedCursorX * screenX, savedCursorY * screenY) end, 50, 1) end else savedCursorX, savedCursorY = getCursorPosition() showCursor(false) end end bindKey("k", "down", togglePanel) I think you understand, if you have a different problem please post it here or create a new topic and tag me 1 Link to comment
Hiding Posted July 4 Author Share Posted July 4 2 hours ago, Shady1 said: There are two kinds of methods, one with setTimer and the other with the alternative onClientRender setTimer : The cursor always appears in the center for one frame after showCursor(true). function openPanel() showCursor(true) -- Save the last cursor position (values between 0 and 1) local x, y = getCursorPosition() -- Get the screen resolution local sx, sy = guiGetScreenSize() -- After 50ms, set the cursor back to its previous position setTimer(function() setCursorPosition(x * sx, y * sy) end, 50, 1) end onClientRender: Use a timer or onClientRender to set the position after showing the cursor. function panelAc() showCursor(true) local x, y = getCursorPosition() local sx, sy = guiGetScreenSize() local function imlecDuzelt() setCursorPosition(x * sx, y * sy) removeEventHandler("onClientRender", root, imlecDuzelt) end addEventHandler("onClientRender", root, imlecDuzelt) end your fixed code : local toggle = false local savedCursorX, savedCursorY local function togglePanel() toggle = not toggle if toggle then showCursor(true) if savedCursorX and savedCursorY then local screenX, screenY = guiGetScreenSize() -- Wait one frame before setting the cursor position setTimer(function() setCursorPosition(savedCursorX * screenX, savedCursorY * screenY) end, 50, 1) end else savedCursorX, savedCursorY = getCursorPosition() showCursor(false) end end bindKey("k", "down", togglePanel) I think you understand, if you have a different problem please post it here or create a new topic and tag me Needed an extra showCursore(false) before the timer showCursor(true) if savedCursorX and savedCursorY then showCursor(false) -- here local screenX, screenY = guiGetScreenSize() setTimer(function() setCursorPosition(savedCursorX * screenX, savedCursorY * screenY) showCursor(true) end, 50, 1) end So now it looks good thank you guys Link to comment
Shady1 Posted July 4 Share Posted July 4 good job, if you have a different problem please post it here or create a new topic and tag m 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now