MOUSEMOVEMENTX: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_MOUSEMOVEMENTX}} The _MOUSEMOVEMENTX function returns the relative horizontal position of the mouse cursor as positive or negative values. {{PageSyntax}} : ''horizontalMove'' = _MOUSEMOVEMENTX * Returns the relative horizontal cursor pixel position compared to the previous cursor position. Negative values are moves to the left. * '''Note:''' A _MOUSESHOW statement will disable _MOUSEMOVEMENTX or _MOUSEMOVEMENTY relative mouse mo...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_MOUSEMOVEMENTX}}
{{DISPLAYTITLE:_MOUSEMOVEMENTX}}
The [[_MOUSEMOVEMENTX]] function returns the relative horizontal position of the mouse cursor as positive or negative values.
The [[_MOUSEMOVEMENTX]] function returns the relative horizontal position of the mouse cursor as positive or negative values.




{{PageSyntax}}  
{{PageSyntax}}
: ''horizontalMove'' = [[_MOUSEMOVEMENTX]]
: ''horizontalMove'' = [[_MOUSEMOVEMENTX]]


Line 9: Line 9:
* Returns the relative horizontal cursor pixel position compared to the previous cursor position. Negative values are moves to the left.
* Returns the relative horizontal cursor pixel position compared to the previous cursor position. Negative values are moves to the left.
* '''Note:''' A [[_MOUSESHOW]] statement will disable [[_MOUSEMOVEMENTX]] or [[_MOUSEMOVEMENTY]] relative mouse movement reads.
* '''Note:''' A [[_MOUSESHOW]] statement will disable [[_MOUSEMOVEMENTX]] or [[_MOUSEMOVEMENTY]] relative mouse movement reads.
* Can also be used to check for any mouse movements to enable a program or close [[Screen Saver Programs]].  
* Can also be used to check for any mouse movements to enable a program or close [[Screen Saver Programs]].
* Sets the mouse to a relative movement mode which can be read by [[_WHEEL]] instead of [[_AXIS]] as mouse [[_DEVICES|device]] 2.
* Sets the mouse to a relative movement mode which can be read by [[_WHEEL]] instead of [[_AXIS]] as mouse [[_DEVICES|device]] 2.




{{PageExamples}}
{{PageExamples}}
''Example 1:'' Since values returned are relative to the last position, the returns can be positive or negative.
; Example 1: Since values returned are relative to the last position, the returns can be positive or negative.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|SCREEN}} 12
{{Cl|SCREEN}} {{Text|12|#F580B1}}
PX = 320: PY = 240 'center position
PX = {{Text|320|#F580B1}}: PY = {{Text|240|#F580B1}} {{Text|<nowiki>'center position</nowiki>|#919191}}
{{Cl|DO...LOOP|DO}}: {{Cl|_LIMIT}} 200
{{Cl|DO}}: {{Cl|_LIMIT}} {{Text|200|#F580B1}}
  {{Cl|DO...LOOP|DO}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}}
    {{Cl|DO...LOOP|DO WHILE}} {{Cl|_MOUSEINPUT}}
    PX = PX + {{Cl|_MOUSEMOVEMENTX}}
        PX = PX + {{Cl|_MOUSEMOVEMENTX}}
    PY = PY + {{Cl|_MOUSEMOVEMENTY}}
        PY = PY + {{Cl|_MOUSEMOVEMENTY}}
  {{Cl|LOOP}}
    {{Cl|LOOP}}
  {{Cl|CLS}}
    {{Cl|CLS}}
  {{Cl|CIRCLE}} (PX, PY), 10, 10
    {{Cl|CIRCLE}} (PX, PY), {{Text|10|#F580B1}}, {{Text|10|#F580B1}}
  {{Cl|LOCATE}} 1, 1: {{Cl|PRINT}} PX, PY
    {{Cl|LOCATE}} {{Text|1|#F580B1}}, {{Text|1|#F580B1}}: {{Cl|PRINT}} PX, PY
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) 'escape key exit '' ''
{{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}({{Text|27|#F580B1}}) {{Text|<nowiki>'escape key exit</nowiki>|#919191}}
{{CodeEnd}}
{{CodeEnd}}


----


''Example 2:'' MOD is used to keep horizontal movement of the circle and cursor inside of the SCREEN 13 window(320).  
; Example 2: MOD is used to keep horizontal movement of the circle and cursor inside of the SCREEN 13 window(320).
{{CodeStart}} '' ''
: Note when using the function this way, then give the user a keypress exit option. Make sure the user has some way to exit that is not dependent on clicking the X button.
{{Cl|SCREEN}} 13, , 1, 0
{{CodeStart}}
{{Cl|DO...LOOP|DO}}: {{Cl|_LIMIT}} 200
{{Cl|SCREEN}} {{Text|13|#F580B1}}, , {{Text|1|#F580B1}}, {{Text|0|#F580B1}}
  {{Cl|DO...LOOP|DO}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}}
{{Cl|DO}}: {{Cl|_LIMIT}} {{Text|200|#F580B1}}
    x = x + {{Cl|_MOUSEMOVEMENTX}}
    {{Cl|DO...LOOP|DO WHILE}} {{Cl|_MOUSEINPUT}}
    y = y + {{Cl|_MOUSEMOVEMENTY}}
        x = x + {{Cl|_MOUSEMOVEMENTX}}
  {{Cl|LOOP}}
        y = y + {{Cl|_MOUSEMOVEMENTY}}
  x = (x + 320) {{Cl|MOD}} 320 'keeps object on screen
    {{Cl|LOOP}}
  y = (y + 200) {{Cl|MOD}} 200 'remove if off screen moves are desired
    x = (x + {{Text|320|#F580B1}}) {{Cl|MOD}} {{Text|320|#F580B1}} {{Text|<nowiki>'keeps object on screen</nowiki>|#919191}}
  {{Cl|CLS}}
    y = (y + {{Text|200|#F580B1}}) {{Cl|MOD}} {{Text|200|#F580B1}} {{Text|<nowiki>'remove if off screen moves are desired</nowiki>|#919191}}
  {{Cl|CIRCLE}} (x, y), 20
    {{Cl|CLS}}
  {{Cl|PCOPY}} 1, 0
    {{Cl|CIRCLE}} (x, y), {{Text|20|#F580B1}}
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> "" 'press any key to exit '' ''
    {{Cl|PCOPY}} {{Text|1|#F580B1}}, {{Text|0|#F580B1}}
{{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} <> {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|<nowiki>'press any key to exit</nowiki>|#919191}}
{{CodeEnd}}
{{CodeEnd}}
: '''NOTE:''' When using the function this way, give the user a keypress exit option. Make sure the user has some way to exit that is not dependent on clicking the X button.




Line 53: Line 54:
* [[_DEVICES]], [[_DEVICEINPUT]]
* [[_DEVICES]], [[_DEVICEINPUT]]
* [[_WHEEL]], [[_LASTWHEEL]]
* [[_WHEEL]], [[_LASTWHEEL]]
* [[_AXIS]], [[_LASTAXIS]]  
* [[_AXIS]], [[_LASTAXIS]]
* [[_MOUSESHOW]], [[_MOUSEHIDE]]
* [[_MOUSESHOW]], [[_MOUSEHIDE]]
* [[Screen Saver Programs]]
* [[Screen Saver Programs]]

Latest revision as of 20:07, 24 March 2024

The _MOUSEMOVEMENTX function returns the relative horizontal position of the mouse cursor as positive or negative values.


Syntax

horizontalMove = _MOUSEMOVEMENTX


  • Returns the relative horizontal cursor pixel position compared to the previous cursor position. Negative values are moves to the left.
  • Note: A _MOUSESHOW statement will disable _MOUSEMOVEMENTX or _MOUSEMOVEMENTY relative mouse movement reads.
  • Can also be used to check for any mouse movements to enable a program or close Screen Saver Programs.
  • Sets the mouse to a relative movement mode which can be read by _WHEEL instead of _AXIS as mouse device 2.


Examples

Example 1
Since values returned are relative to the last position, the returns can be positive or negative.
SCREEN 12
PX = 320: PY = 240 'center position
DO: _LIMIT 200
    DO WHILE _MOUSEINPUT
        PX = PX + _MOUSEMOVEMENTX
        PY = PY + _MOUSEMOVEMENTY
    LOOP
    CLS
    CIRCLE (PX, PY), 10, 10
    LOCATE 1, 1: PRINT PX, PY
LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit

Example 2
MOD is used to keep horizontal movement of the circle and cursor inside of the SCREEN 13 window(320).
Note when using the function this way, then give the user a keypress exit option. Make sure the user has some way to exit that is not dependent on clicking the X button.
SCREEN 13, , 1, 0
DO: _LIMIT 200
    DO WHILE _MOUSEINPUT
        x = x + _MOUSEMOVEMENTX
        y = y + _MOUSEMOVEMENTY
    LOOP
    x = (x + 320) MOD 320 'keeps object on screen
    y = (y + 200) MOD 200 'remove if off screen moves are desired
    CLS
    CIRCLE (x, y), 20
    PCOPY 1, 0
LOOP UNTIL INKEY$ <> "" 'press any key to exit


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link