[MEH] lock mouse cursor

  • #1, z sebastianFriday, 02. September 2016, 18:58 hodinky 8 years ago
    hey there,

    short question : is it possible to lock the cursors position but maintain its left/right click ability?

    Kapitán

    2346 Posts


  • #2, z ke4Friday, 02. September 2016, 19:06 hodinky 8 years ago
    Maybe you could have a loop that would be constantly setting a cursor position.

    Zabiják klíčů

    810 Posts

  • #3, z afrlmeFriday, 02. September 2016, 19:34 hodinky 8 years ago
    What Ke4 says sounds quite plausible. Why is it that you are wanting to lock the cursor position? The player would still be able to fight with it a little bit, but considering the system loops every 4ms+ they shouldn't be able to move the cursor all that much.

    So yeah, a basic mainLoop event should do the trick - jump to action part #? method may not work fast enough because you have to add a pause action part into the loop somewhere otherwise it will timeout the engine after a few seconds or so of running the loop. The Lua loop functions "repeat" & "while" also seem to time out the engine most of the time too.

    definition script...
    function initFCPos(x, y)
     cpos = {x = x, y = y}  -- store x, y cursor position values
     registerEventHandler("mainLoop", "forceCPos") -- start the loop
    end
    
    function forceCPos()
     setCursorPos({ x = (game.ScrollPosition.x + cpos.x), y = (game.ScrollPosition.y + cpos.y) }) -- update cursor position
    end
    
    function endFCPos()
     unregisterEventHandler("mainLoop", "forceCPos") -- kill the loop
    end
    

    to use... (start force cursor position loop)
    initFCPos(400, 250) -- start the loop & define the cursor position
    

    to use... (end force cursor position loop)
    endFCPos() -- kill the loop
    

    Imperátor

    7285 Posts

  • #4, z ke4Friday, 02. September 2016, 20:09 hodinky 8 years ago
    theoretically you could even have an aplha image for your cursor so it would not be visible & static image of your cursor in your scene, where you need to.

    + one big object over all the scene ( no image, just an action area ) so all the other objects would not get active if you would hover over them, plus this object could have the left / right click actions you need and it would not matters what the current position of the cursor is.

    Zabiják klíčů

    810 Posts

  • #5, z sebastianFriday, 02. September 2016, 20:23 hodinky 8 years ago
    the thing is i need to have several places on the screen which should remain clickable but the cursor should snap to their location when moving the cursor

    Kapitán

    2346 Posts

  • #6, z afrlmeFriday, 02. September 2016, 22:24 hodinky 8 years ago
    @ Ke4: interface would be better than a scene object with interaction polygon as the active state of the current cursor would be set to active permanently while it's displayed.

    @ Sebastian: the script I provided you with should suffice. You can update the positions while loop is already active too by updating the cpos table inside of an execute a script action.

    I think I understand what you are getting at. You could check the direction the cursor is being dragged towards, & maybe use a table which contains all the positions & check what's above, below, to the side of each table or something to determine which thing to move cursor over towards.

    Imperátor

    7285 Posts

  • #7, z sebastianSaturday, 03. September 2016, 00:41 hodinky 8 years ago
    thanks for the script. I will try out tomorrow.

    Id like to do one thing:
    When using a gamapad and saving the game i blend in an onscreen keyboard to name the save file (string gets saved in an additional file besides the bookmarkXX.dat).
    Instead of moving the cursor over each button id like to get the cursor over a button and fix it there until i move it to the next key. And by moving i mean directly select it.

    This would be easy to do when only using Mouse/Keyboard OR Gamepad. But what if i use the gamepad to point on one key and then using a mouse which is freely moveable?

    So I need to only accept one input method when onscreen keyboard is on: snapping to the keys -when using controller OR mouse.
    Is it maybe possible to change the mouse speed, too?

    A further possible way for this "snapping" I want to use is for gamepad controls inside the game itself. The cursor could move from object to object on the screen. This could be done by checking the x/y pos from the focused char and x/y object destination ...

    Kapitán

    2346 Posts

  • #8, z afrlmeSaturday, 03. September 2016, 02:31 hodinky 8 years ago
    Mouse should move as fast as you can move your hand, no? My mouse has a button for adjusting DPI, but I can't say I ever use it & no I don't think you can adjust the mouse speed via VS. - You are using a mac? If so I'm pretty sure I recall a few people mentioning the mouse seems to move sluggish on the mac for some reason.

    As for saves, you are talking about an autosave system, yes? Regular save menu will always default to the first empty slot it comes across starting from index 1 unless you click on a slot that already contains a save file.

    You could hide the mouse to do the snapping stuff. Lua key event (keyboard / gamepad) & mouse event handlers should work regardless of cursor being hidden, or if you if a text is currently being displayed or you have a cut-scene event playing.

    Imperátor

    7285 Posts

  • #9, z sebastianSaturday, 03. September 2016, 14:30 hodinky 8 years ago
    yes, mouse moves as fast as it is set in the computers preferences (or by driver). My thought was that this may cause trouble because the mouse is definitely faster than the gamepad mouse move. By setting the mouse speed to e.g. "0" it is locked i guess. Thats why i asked for it^^

    I for myself are talking about the autosave system with a possibility to name my savestates with keyboard. Because we can't recognize if a gamepad is used (yet) and store it into a value, I have to support gamepad and mouse controls for this onscreen keyboard But moving the mouse cursor with the gamepad in its regular speed over each key is a bit painful. so -when activating the onscreen keyboard- I need to lock the cursor to the keys and when moving the mouse (with controller or mouse itself) it should jump to the next key regarding in which direction I moved the cursor.

    I hope your last suggestion will work. The keys itself have "left click" actions to simulate key press. When hiding the cursor via the action part I don't know if creating a LeftClick event will do... But i will test this out smile
    Otherwise I will try to hide the cursor by using a blank image...

    Kapitán

    2346 Posts

  • #10, z afrlmeSaturday, 03. September 2016, 14:53 hodinky 8 years ago
    You should be able to control the speed of the cursor with the gamepad analog sticks based on amount if tilt applied to the stick. It may even be possible to add acceleration to the movement too by having it start slow & build up to the tilt value - theoretical on my part.

    P.S: technically you don't have to trigger left click. You could use an if query with values or something, so any key press should suffice. Also it's possible to check if cursor or something else is inside of a polygon, so you could even devise something like an animation & check if it's located at x coordinate or within a certain polygon area. So many different methods you could apply.

    Imperátor

    7285 Posts

  • #11, z sebastianSaturday, 03. September 2016, 23:04 hodinky 8 years ago
    I guess for the onboard keyboard i discontinue this feature.
    The analog stick controls of the gamepad should be slow enough to precisely stop at every key and the mouse as it is should be exact pointing (if the keyboard is really needed here)
    But as mentioned maybe there are more possibilities for me to use this feature in another scenario.

    Thanks anyway

    Kapitán

    2346 Posts