Author Topic: problem with the mouse  (Read 3956 times)

0 Members and 1 Guest are viewing this topic.

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
problem with the mouse
« on: February 16, 2022, 06:06:28 am »
Good morning / good evening to all

Can someone explain the mouse behavior?

At every pressure of CTRL+a (but also any other combination or key) the cursor, instead of staying still where it is, moves on the X and Y axes (mostly upwards).

Why? And how to avoid this?

Thank You...


Code: QB64: [Select]
  1. SCREEN _newIMAGE (800,600,32)
  2.  
  3.  
  4.         j$=inkey$
  5.  
  6.         while _mouseinput : wend
  7.  
  8.         if j$=chr$(1) then  ' CTRL+a
  9.                 _SCREENCLICK _screenX + _mousex ,  _screenY + _mousey
  10.         end if
  11.  
  12.         locate 10,1: print _mousex , _mousey
  13.  
  14. loop until j$=chr$(27)
  15.  

« Last Edit: February 16, 2022, 06:12:42 am by krovit »
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: problem with the mouse
« Reply #1 on: February 16, 2022, 06:49:27 am »
You're not taking the title bar into account.   I've simplified your code a little - press ANY key.
Why the x correction of 4 is required to keep the mouse stationary I don't understand.

Code: QB64: [Select]
  1. Screen _NewImage(800, 600, 32)
  2.     i$ = InKey$
  3.     Locate 10, 10: Print Using "##### "; _MouseX; _MouseY
  4. Loop Until i$ = Chr$(27)
  5.  
It works better if you plug it in.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: problem with the mouse
« Reply #2 on: February 16, 2022, 06:52:31 am »
The 4 might be the window border throwing numbers off.  At least, that's my guess.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: problem with the mouse
« Reply #3 on: February 16, 2022, 07:15:48 am »
Thank you Richard, very kind

I didn't expect to have to insert a corrector on the X / Y axes, also because the mouse range doesn't take into account the title bar and the window borders.

It also seemed that correcting the position was a clumsy fallback: you should know the reason for each behavior before "correcting" an unexpected result.

Probably if windows were set in some particular way also the corrector should be varied (maybe he means this SMcNell).  For example, in my case, I have to put "26" and not "27".

However I believe that the argument has been useful to all :)


Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: problem with the mouse
« Reply #4 on: February 16, 2022, 08:03:49 am »
https://qb64forum.alephc.xyz/index.php?topic=1020.msg138098#msg138098

You can get your heights/widths from the routines in the topic above.

 QB64: [Select]
DECLARE LIBRARY
    FUNCTION glutGet& (BYVAL what&)
END DECLARE
 
_SCREENMOVE 200, 200 'We moved our screen to 200,200 so we know these values are correct
BorderWidth = glutGet(506)
TitleBarHeight = glutGet(507)
ActualScreenX = glutGet(100)
ActualScreenY = glutGet(101)
 
PRINT "Actual Top Left of screen is at ("; _SCREENX; ","; _SCREENY; ")"
PRINT "The border is "; BorderWidth; "pixels"
PRINT "And the title bar is"; TitleBarHeight; " pixels"
PRINT "So your actual display starts at ("; ActualScreenX; ","; ActualScreenY; ")"
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: problem with the mouse
« Reply #5 on: February 16, 2022, 09:07:37 am »
Thanks SMcNelly, to avoid surprises so it's even better!

The problem is not yet completely solved but I believe that the road to a solution passes from here
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: problem with the mouse
« Reply #6 on: February 17, 2022, 11:39:43 am »
Funny!
Code: QB64: [Select]
  1. Screen _NewImage(800, 600, 32)
  2.     Cls
  3.     i$ = InKey$
  4.     If Len(i$) Then _ScreenClick _ScreenX + 50, _ScreenY + 10
  5.     _Display
  6.     _Limit 10
  7. Loop Until i$ = Chr$(27)
  8.  
  9.  

Now try this!
Code: QB64: [Select]
  1. Screen _NewImage(800, 600, 32)
  2.     Cls
  3.     i$ = InKey$
  4.     If Len(i$) Then _ScreenClick _ScreenX + 20, _ScreenY + 10
  5.     _Display
  6.     _Limit 10
  7. Loop Until i$ = Chr$(27)
  8.  

No popup window like when you click a regular app there (on app icon) just closes down. (Same with .exe)

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: problem with the mouse
« Reply #7 on: February 19, 2022, 03:09:50 am »
Yes bplus... what happens is understandable but it seems a little strange behavior
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)