QTIPS - Use of Mouse
Published By | Date | Version | Knowledge Level | Keywords |
---|---|---|---|---|
Sprezzatura Ltd | 01 DEC 1991 | 2.1+ | EXPERT | MOUSE, MOUSE_SUBS, MOUSE_INIT, MOUSE_DEFINITION_SUB, RBASIC, MOUSE_TEST, %%MOUSEVARS%%, INPUT.CHAR, @DATA |
Jim Owen asks "What commands can I use to access the mouse interface in an R/Basic program?". The answer is that there are several routines available for manipulating the mouse, a SELECT VERBS "[MOUSE]" reveals these to be MOUSE_TEST (used to check for mouse input), MOUSE_INIT (used to initialise the mouse system information), MOUSE_DEFINITION_SUB (commuter program for Mouse windows) and the assembler routine MOUSE_SUBS. These routines manipulate a system labelled common area %%MOUSEVARS%%.
Mouse_Test
This is the equivalent of INPUT.CHAR for mouse actions. It is used to check whether a mouse motion has been made or if a mouse key/key combination has been pressed. If such an action has been taken then the keystrokes will be returned from the function and, if applicable, in @DATA. Thus if the mouse motion was down and left, the left key press would be returned in @DATA and the down keypress as the result of the function. The order of return appears to be that Button Presses take precedence over Y movements which in turn take precedence over X movements. Those actions with precedence will be returned from the function (which seems only ever to return 1 keystroke), those remaining, in @DATA.
Mouse_Definition_Sub
This is the commuter program for the mouse environment window, which is therefore of no use to the developer. It is interesting to note that my mouse always claims to be a bus mouse when it is in fact a serial mouse. Currently it is unsure whether this is due to a bug in the mouse driver or in MOUSE_SUBS.
Mouse_Subs
This is an assembler subroutine that takes 8 parameters. As with other assembler programs, the purpose of each parameter can change from call to call, but basically the first parameter is the code, or action to be taken, and the eighth is a result flag (set to 1 for success, 0 for failure). The codes that have been identified thus far, along with their operands, are presented below (see Note 1 for information regarding XPos and Ypos).
ÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄ Code³ Description ³ XPos ³ YPos ³4th Var³5th Var³ Key ³ # of ³ Flag ³ ³ ³ ³ ³ ³ Pressed³ Buttons³ ÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄ 0 ³ Get Number ³ n/a ³ n/a ³ n/a ³ n/a ³ n/a ³ # of ³ 1/0 ³ of Buttons ³ ³ ³ ³ ³ ³ Buttons³ ÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄ 3 ³ Get Mouse ³ Xpos ³ YPos ³ n/a ³ n/a ³ Mouse ³ n/a ³ 1/0 ³ Location ³ ³ ³ ³ ³ Key ³ ³ ³ ³ ³ ³ ³ ³ Pressed³ ³ ³ ³ ³ ³ ³ ³(Note 2)³ ³ ÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄ 4 ³ Update Mouse³ Xpos ³ Ypos ³ n/a ³ n/a ³ n/a ³ n/a ³ 1/0 ³ Location ³ ³ ³ ³ ³ ³ ³ ÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄ 15 ³ Set Motion ³XRatio ³YRatio ³ n/a ³ n/a ³ n/a ³ n/a ³ 1/0 ³ to Pixel ³(1 to ³(1 to ³ ³ ³ ³ ³ ³ Ratios (ie ³32767) ³32767) ³ ³ ³ ³ ³ ³ sensitivity,³ ³ ³ ³ ³ ³ ³ ³ higher the ³ ³ ³ ³ ³ ³ ³ ³ X and Y the ³ ³ ³ ³ ³ ³ ³ ³ lower the ³ ³ ³ ³ ³ ³ ³ ³ sensitivity)³ ³ ³ ³ ³ ³ ³ ÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄ 36 ³ Get Version ³Integer³Decimal³ n/a ³ n/a ³ n/a ³ n/a ³ 1/0 ³ Number of ³portion³portion³ ³ ³ ³ ³ ³ Mouse Driver³of ³of ³ ³ ³ ³ ³ ³ ³version³version³ ³ ³ ³ ³ ÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄ
Note 1 - Please note that these X and Y positions are not directly related to the position on screen but rather are related to the last X/Y position of the mouse. This can be tested against the previous value stored in labelled common. (q.v.). Normally a 0.25:1 correlation between X/Y position and XPos/YPos value (eg XPos = 24, X = 6) can be obtained by initialising the values to 0 using a 4 call and resetting them to the maximum when the maximum is exceeded.
Note 2 - The Mouse Key Pressed will be an integer corresponding to fields 1 through 7 of the Mouse Record in labelled common (q.v.)
As an example of how Mouse_Subs may be used directly, consider the section of code on the page following. It is designed to be used when the mouse driver has already been installed and simply indicates on screen what is happening to the cursor.
%%MOUSEVARS%%
%%MOUSEVARS%% is a system labelled common area having four variables as follows
common /%%MOUSEVARS%%/ A, B, C, D
where
A | The last X position reported by the mouse driver |
B | The last Y position reported by the mouse driver |
C | Set to true if the mouse is active, false otherwise |
D | The current Mouse Details, a field mark delimited dynamic array having the following structure < 1 > Key definition for left mouse button < 2 > Key definition for right mouse button < 3 > Key definition for left and right mouse buttons together < 4 > Key definition for centre mouse button < 5 > Key definition for left and centre mouse buttons together < 6 > Key definition for right and centre mouse buttons together < 7 > Key definition for all three mouse buttons together < 8 > Mouse type (?) < 9 > X Ratio < 10 > Y Ratio < 11 > Multivalued array having 6 values, each value being the X pixel to character ratio for < 11, 1 > Windows < 11, 2 > Editor < 11, 3 > Pop Ups < 11, 4 > Menus < 11, 5 > Paint < 11, 6 > Default < 12 > Multivalued array having 6 values, each value being the Y pixel to character ration with a structure as < 11 >. < 13 > Not used on the mouse tested < 14 > Mouse software version < 15 > Number of buttons on the mouse |
LX = 0 ; LY = 0 ; DUMMY = 0 ; XPOS = 0 ; YPOS = 0 BUTTON_PRESSED = 0 ; FLAG = 0 ; EXIT_SET = 0 print @(0,0) : * Tell mouse driver where it is CALL MOUSE_SUBS( 4, 1,1, DUMMY, DUMMY, BUTTON_PRESSED, DUMMY, FLAG) loop * check X and Y positions CALL MOUSE_SUBS_RTI( 3, XPOS, YPOS, DUMMY, DUMMY, BUTTON_PRESSED, DUMMY, ----> FLAG) until EXIT_SET do CHANGED = 0 if XPOS > LX then print @(0,0) : "Moving Right" "L#20" CHANGED = 1 end else if XPOS < LX then CHANGED = 1 print @(0,0): "Moving Left" "L#20" end end if YPOS > LY then CHANGED = 1 print @(0,0) : "Moving Down" "L#20" end else if YPOS < LY then CHANGED = 1 print @(0,0): "Moving Up" "L#20" end end if CHANGED then /* Note that there is a 4:1 relationship between XPOS and YPOS and screen positions. Remove previous screen marker then print current */ print @(LX/4,LY/4): " " print @(xpos/4,ypos/4): "*" : @(xpos/4,ypos/4) : end LY = YPOS LX = XPOS if BUTTON_PRESSED then print @(0,0) : "Key " : BUTTON_PRESSED "L#20" if button_pressed = 3 then /* Note this means that for a standard 2 button mouse both buttons have been pressed at once indicating Quit! */ BUTTON_PRESSED = "" @DATA = "" stop end BUTTON_PRESSED = "" end repeat
(Volume 3, Issue 7, Pages 12-15)