|
|||||||
QTIPS - Use of MouseJim 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_TestThis 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_SubThis 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_SubsThis 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 0001 LX = 0 ; LY = 0 ; DUMMY = 0 ; XPOS = 0 ; YPOS = 0 0002 BUTTON_PRESSED = 0 ; FLAG = 0 ; EXIT_SET = 0 0003 print @(0,0) : 0004 * Tell mouse driver where it is 0005 CALL MOUSE_SUBS( 4, 1,1, DUMMY, DUMMY, BUTTON_PRESSED, DUMMY, FLAG) 0006 loop 0007 * check X and Y positions 0008 CALL MOUSE_SUBS_RTI( 3, XPOS, YPOS, DUMMY, DUMMY, BUTTON_PRESSED, DUMMY, 0009 ----> FLAG) 0010 until EXIT_SET do 0011 CHANGED = 0 0012 if XPOS > LX then 0013 print @(0,0) : "Moving Right" "L#20" 0014 CHANGED = 1 0015 end else 0016 if XPOS < LX then 0017 CHANGED = 1 0018 print @(0,0): "Moving Left" "L#20" 0019 end 0020 end 0021 if YPOS > LY then 0022 CHANGED = 1 0023 print @(0,0) : "Moving Down" "L#20" 0024 end else 0025 if YPOS < LY then 0026 CHANGED = 1 0027 print @(0,0): "Moving Up" "L#20" 0028 end 0029 end 0030 if CHANGED then 0031 /* 0032 Note that there is a 4:1 relationship between XPOS and YPOS and 0033 screen positions. Remove previous screen marker then print current 0034 */ 0035 print @(LX/4,LY/4): " " 0036 print @(xpos/4,ypos/4): "*" : @(xpos/4,ypos/4) : 0037 end 0038 LY = YPOS 0039 LX = XPOS 0040 if BUTTON_PRESSED then 0041 print @(0,0) : "Key " : BUTTON_PRESSED "L#20" 0042 if button_pressed = 3 then 0043 /* 0044 Note this means that for a standard 2 button mouse both buttons have 0045 been pressed at once indicating Quit! 0046 */ 0047 BUTTON_PRESSED = "" 0048 @DATA = "" 0049 stop 0050 end 0051 BUTTON_PRESSED = "" 0052 end 0053 repeat (Volume 3, Issue 7, Pages 12-15) |
|||||||
| |||||||