Best method to distinguish Touch/Mouse event in a project that uses both?

0 favourites
  • 13 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • I'm trying to make a game that would work on PC with mouse and on mobile with touch, so I'm using both plugins. Touch plugin has "Use mouse input=YES", because I want it to handle most touch and left click events in the project.

    But I still need to be able to distinguish between left mouse click and touch - to update the UI, hints etc. What's the best way to do it?

    At the moment I have this:

    But I'm worried it may not work on some devices.

    Tagged:

  • There's also the platform info plugin which could help here. That's what I'm using, although it does warn that it is not a surefire way.

    construct.net/en/make-games/manuals/construct-3/plugin-reference/platform-info

    But pair that with an additional check like so (that's the scirra recommended method)

    editor.construct.net

    And it should probably cover like 99% of the cases.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The mouse cursor is aways on the screen.

    Just use is overlapping with a dummy object.

  • PlatformInfo isn't really a solution. I don't need to detect the platform. I need to know when "On Touch" is triggered - whether it was really a touch event or a mouse click.

    That official example is using Touch with mouse input disabled.

    Just use is overlapping with a dummy object.

    Not sure I understand how it would help. Say, when playing on Steam Deck, you can use the touchpad (mouse) or touch the screen. Or even connect an external mouse.

  • If you know the dummy was overlapping you know it was mouse.

  • Newts solution is interesting. I've also found this bit of js that appears to work from my brief testing.

    if(window.matchMedia("(any-pointer: coarse)").matches) {
     runtime.objects.Sprite.getFirstInstance().x += 10;
    } else {
    	runtime.objects.Sprite.getFirstInstance().x -= 10;
    }

    There's probably some caveats to this so beware and check this article

    css-tricks.com/interaction-media-features-and-their-potential-for-incorrect-assumptions

    Seems to be fairly well supported too with 97%+ coverage

    caniuse.com/css-media-interaction

  • If you know the dummy was overlapping you know it was mouse.

    What if it's a touch and the mouse cursor just happened to be in the same spot?

  • > If you know the dummy was overlapping you know it was mouse.

    What if it's a touch and the mouse cursor just happened to be in the same spot?

    That would mean that the user is dragging while touching, so I guess you could check that its speed is zero or pretty close, and/or mouse is down.

    The number of corner cases is just going to balloon if you insist on working both in at the same time. Plus the logic for UI over the entire screen is vastly different between the two, especially if you want zones where the user can click on both UI, and background.

    Letting the user decide and have events for both may be the best method.

  • Did this example helpful to you?

    #open=detecting-input-method

  • Thanks for the replies! I just realized that Touch plugin with "Use mouse input" enabled treats all clicks as touches, not just left clicks. So simply replacing mouse events with similar touch events won't be possible. I'll have to duplicate some events, create OR-blocks with triggers, perhaps add a bunch of helper functions like "IsTouchOrMouseLeftClick". Oh, well..

  • Yeah when I was doing dev I would just use touch, and not use mouse.

    You loose a cursor, and the ability to mouse over. Not a real big loss.

  • If you want to tell apart mouse and touch input, I'd recommend disabling 'Use mouse input' on the Touch input and making separate sets of events for input. You can do things like call functions to avoid duplicating logic. The 'Use mouse input' setting is intended as a shortcut if you don't need to tell the difference between mouse and touch input, so if you do, it's not really the right setting to use. Any other approach I'd say is pretty much a hack and may well not work reliably, as some devices support both mouse and touch input, so the only way to truly know if an input is a mouse or a touch input is to handle them separately.

  • I do this:

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)