Touchscreen and DisplayPopupMenu()

Just starting out? Need help? Post your questions and find answers here.
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Touchscreen and DisplayPopupMenu()

Post by Dirk Geppert »

Hi,

the manual says for DisplayPopupMenu(#Menu) : "Displays a PopupMenu under the current mouse position or at the given screen location".

On devices with no mouse, likes phones or Touchscreens in generell, the menu appears on top left (0, 0) of the Screen.
Is there a way to determine the coordinates of a TouchScreen tap? Then I could store and use it with OpenMenu...

Ciao dige
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: Touchscreen and DisplayPopupMenu()

Post by falsam »

Works with an Android terminal.

Code: Select all

Declare DisplayMenuPopUp()
Declare IsMobileDevice()

;Remove debug window
!$('div').eq(0).remove()

OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_Background)

If CreatePopupMenu(0)
  MenuItem(1, "item 1")
  MenuItem(2, "item 2")
  MenuItem(3, "etc ...")
EndIf

If IsMobileDevice()
  BindEvent(#PB_Event_LeftClick, @DisplayMenuPopUp())
Else
  BindEvent(#PB_Event_RightClick, @DisplayMenuPopUp())
EndIf

Procedure DisplayMenuPopUp()
  DisplayPopupMenu(0, WindowID(0))
EndProcedure

Procedure IsMobileDevice()  
  !if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  !   return true;
  ! } else {
  !   return false;
  ! }
EndProcedure
Test with an apk ;)

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: Touchscreen and DisplayPopupMenu()

Post by falsam »

I could have used DeviceInfo(#PB_Device_Platform) to determine if I am on a mobile terminal ....

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
User avatar
majikeyric
Posts: 7
Joined: Mon Feb 24, 2014 11:07 pm
Contact:

Re: Touchscreen and DisplayPopupMenu()

Post by majikeyric »

DeviceInfo() is not reliable, I personnaly call the Mobile Detect PHP script (http://mobiledetect.net/) at the beginning of my apps.
Post Reply