Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Add blocks for detecting mobile devices/touchscreen

    Feedback
    feature-request
    2
    4
    118
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jeffreyrb03-gmail
      JaecadeJnight Mod Helper last edited by

      I have somewhat of a solution to this by regex checking if the user agent contains “Android” or “Mobi” or some other stuff (to see if a user is using mobile), but JavaScript provides other methods like checking navigator.maxTouchPoints (to check for touchscreen) and all.

      I want to use this to detect if the user is using mobile/touchscreen, and then provide joysticks for my 3D scene. I propose two new blocks:

      • Sensing reporter block: (is touchscreen?) , uses navigator.maxTouchPoints and checks if it is above 0. If it is above 0 then there’s touchscreen, but if it isn’t then its a computer.
      • Sensing reporter block: (is mobile?) , is more general, and would generally mean touchscreen and no keyboard. This would be most useful for detecting then adding joysticks in my code.

      My current method for seeing is the user agent is mobile is also kind of frowned upon and doesn’t always work because users can enable “Desktop mode” in their mobile browsers which would make the game unplayable. There’s also like different browsers too

      #LLJW
      <span style="color:white;background-image:linear-gradient(to right, lightblue, navy)">My name is Jeff</span>

      1 Reply Last reply Reply Quote 1
      • Tyller_
        Tyller_ Best Forum Helpers last edited by

        @jeffreyrb03-gmail I dont think you can directly detect touchscreen but you can definetly detect if its mobile (like you said with user agent) because devices might not broadcast touch screen support, though you could detect as soon as a touch is detected, though I think you have to detect touch differently than mouse clicks (pretty sure) so you can even detect if touchscreen was last used

        <div component="post/signature" data-uid="255" class="post-signature">Check out my chat room project so you ppl can not use forums as chat rooms! https://play.creaticode.com/projects/66f2e1dcd1be43d82b886fbd?version=1 <p dir="auto">
        </div>

        jeffreyrb03-gmail 1 Reply Last reply Reply Quote 0
        • jeffreyrb03-gmail
          JaecadeJnight Mod Helper @Tyller_ last edited by

          @tyller_ yeah true, ontouchstart events and navigator.maxTouchPoints do mean touchscreen tho

          #LLJW
          <span style="color:white;background-image:linear-gradient(to right, lightblue, navy)">My name is Jeff</span>

          Tyller_ 1 Reply Last reply Reply Quote 0
          • Tyller_
            Tyller_ Best Forum Helpers @jeffreyrb03-gmail last edited by

            @jeffreyrb03-gmail yeah but with some touchscreen it allows for mouse and touchscreen, so maybe header blocks for when touchscreen started and when non touchscreen started? or just a booolean for if touchscreen is in use (whether last press was mouse or touchscreen) then manually detect changes and run scripts (toggling joysticks etc)

            <div component="post/signature" data-uid="255" class="post-signature">Check out my chat room project so you ppl can not use forums as chat rooms! https://play.creaticode.com/projects/66f2e1dcd1be43d82b886fbd?version=1 <p dir="auto">
            </div>

            1 Reply Last reply Reply Quote 1
            • First post
              Last post