MOUSEINPUT: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 21: | Line 21: | ||
{{Cl|PRINT}} {{Cl|_MOUSEX}}, {{Cl|_MOUSEY}}, {{Cl|_MOUSEBUTTON}}(1), {{Cl|_MOUSEWHEEL}} | {{Cl|PRINT}} {{Cl|_MOUSEX}}, {{Cl|_MOUSEY}}, {{Cl|_MOUSEBUTTON}}(1), {{Cl|_MOUSEWHEEL}} | ||
{{Cl|LOOP}} | {{Cl|LOOP}} | ||
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> "" | {{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> "" | ||
{{CodeEnd}} | {{CodeEnd}} | ||
: ''Explanation:'' The latest mouse function status can be read after the loop. [[_LIMIT]] and [[_DELAY]] loops will slow returns down. | : ''Explanation:'' The latest mouse function status can be read after the loop. [[_LIMIT]] and [[_DELAY]] loops will slow returns down. | ||
Line 43: | Line 43: | ||
{{Cl|END IF}} | {{Cl|END IF}} | ||
{{Cl|END IF}} | {{Cl|END IF}} | ||
{{Cl|LOOP}} | {{Cl|LOOP}} | ||
' your program code | ' your program code | ||
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) | {{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) | ||
{{CodeEnd}} | {{CodeEnd}} | ||
Line 54: | Line 54: | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|PRINT}} "Press I to enter input! Press Q to quit" | {{Cl|PRINT}} "Press I to enter input! Press Q to quit" | ||
{{Cl|DO...LOOP|DO}} | {{Cl|DO...LOOP|DO}} | ||
K$ = {{Cl|UCASE$}}({{Cl|INKEY$}}) | K$ = {{Cl|UCASE$}}({{Cl|INKEY$}}) | ||
{{Cl|DO...LOOP|DO}} | {{Cl|DO...LOOP|DO}} | ||
{{Cl|IF...THEN|IF}} {{Cl|_MOUSEBUTTON}}(1) = -1 {{Cl|THEN}} {{Cl|PRINT}} "*" 'indicates a mouse click event | {{Cl|IF...THEN|IF}} {{Cl|_MOUSEBUTTON}}(1) = -1 {{Cl|THEN}} {{Cl|PRINT}} "*" 'indicates a mouse click event | ||
{{Cl|LOOP}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}} | {{Cl|LOOP}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}} | ||
{{Cl|IF...THEN|IF}} K$ = "Q" {{Cl|THEN}} {{Cl|END}} | {{Cl|IF...THEN|IF}} K$ = "Q" {{Cl|THEN}} {{Cl|END}} | ||
{{Cl|IF...THEN|IF}} K$ = "I" {{Cl|THEN}} 'press I to enter text | {{Cl|IF...THEN|IF}} K$ = "I" {{Cl|THEN}} 'press I to enter text | ||
{{Cl|INPUT}} "Click the mouse and enter something: ", entry$ 'enter some text | {{Cl|INPUT}} "Click the mouse and enter something: ", entry$ 'enter some text | ||
{{Cl|GOSUB}} Clickcheck 'clear mouse data | {{Cl|GOSUB}} Clickcheck 'clear mouse data | ||
{{Cl|END IF}} | {{Cl|END IF}} | ||
{{Cl|LOOP}} | {{Cl|LOOP}} | ||
{{Cl|END}} | {{Cl|END}} | ||
Clickcheck: | Clickcheck: | ||
count = 0 | count = 0 | ||
{{Cl|DO...LOOP|DO}} | {{Cl|DO...LOOP|DO}} | ||
count = count + 1 | count = count + 1 | ||
{{Cl|LOOP}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}} | {{Cl|LOOP}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}} | ||
{{Cl|PRINT}} count 'returns the number of loops before mouse data is cleared | {{Cl|PRINT}} count 'returns the number of loops before mouse data is cleared | ||
{{Cl|RETURN}} | {{Cl|RETURN}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
:''Explanation:'' Click the mouse a few times while entering [[INPUT]] text. When Enter is pressed, the number of loops are displayed. | :''Explanation:'' Click the mouse a few times while entering [[INPUT]] text. When Enter is pressed, the number of loops are displayed. | ||
Line 80: | Line 80: | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [https://qb64phoenix.com/forum/showthread.php?tid=1165 Featured in our "Keyword of the Day" series] | |||
* [[_MOUSEX]], [[_MOUSEY]], [[_MOUSEBUTTON]], [[_MOUSEWHEEL]] | * [[_MOUSEX]], [[_MOUSEY]], [[_MOUSEBUTTON]], [[_MOUSEWHEEL]] | ||
* [[_MOUSESHOW]], [[_MOUSEHIDE]], [[_MOUSEMOVE]] | * [[_MOUSESHOW]], [[_MOUSEHIDE]], [[_MOUSEMOVE]] | ||
Line 86: | Line 87: | ||
{{PageNavigation}} | {{PageNavigation}} | ||
Latest revision as of 17:46, 25 May 2024
The _MOUSEINPUT function is used to monitor any new mouse positions, button presses or movements of the scroll wheel. Must be called before other mouse information becomes available.
Syntax
- infoExists%% = _MOUSEINPUT
Description
- Returns -1 if new mouse information is available, otherwise it returns 0.
- Must be called before reading any of the other mouse functions. The function will not miss any mouse input even during an INPUT entry.
- Use in a loop to monitor the mouse buttons, scroll wheel and coordinate positions.
- To clear all previous mouse data, use _MOUSEINPUT in a loop until it returns 0.
Examples
Example 1: Mouse coordinate, click and scroll events are returned sequentially inside of a _MOUSEINPUT loop.
DO DO WHILE _MOUSEINPUT ' Check the mouse status PRINT _MOUSEX, _MOUSEY, _MOUSEBUTTON(1), _MOUSEWHEEL LOOP LOOP UNTIL INKEY$ <> "" |
- Explanation: The latest mouse function status can be read after the loop. _LIMIT and _DELAY loops will slow returns down.
Example 2: How to use a _MOUSEINPUT loop to locate PSET positions on a screen using a right mouse button click.
SCREEN 12 DO ' main program loop ' your program code DO WHILE _MOUSEINPUT'mouse status changes only x = _MOUSEX y = _MOUSEY IF x > 0 AND x < 640 AND y > 0 AND y < 480 THEN IF _MOUSEBUTTON(2) THEN PSET (x, y), 15 LOCATE 1, 1: PRINT x, y END IF END IF LOOP ' your program code LOOP UNTIL INKEY$ = CHR$(27) |
Example 3: Clearing any mouse data read before or during an INPUT entry. Press "I" to enter input:
PRINT "Press I to enter input! Press Q to quit" DO K$ = UCASE$(INKEY$) DO IF _MOUSEBUTTON(1) = -1 THEN PRINT "*" 'indicates a mouse click event LOOP WHILE _MOUSEINPUT IF K$ = "Q" THEN END IF K$ = "I" THEN 'press I to enter text INPUT "Click the mouse and enter something: ", entry$ 'enter some text GOSUB Clickcheck 'clear mouse data END IF LOOP END Clickcheck: count = 0 DO count = count + 1 LOOP WHILE _MOUSEINPUT PRINT count 'returns the number of loops before mouse data is cleared RETURN |
- Explanation: Click the mouse a few times while entering INPUT text. When Enter is pressed, the number of loops are displayed.
See also
- Featured in our "Keyword of the Day" series
- _MOUSEX, _MOUSEY, _MOUSEBUTTON, _MOUSEWHEEL
- _MOUSESHOW, _MOUSEHIDE, _MOUSEMOVE
- Controller Devices