How to operate the mouse

Publisher:明石轩Latest update time:2012-04-16 Keywords:Mouse Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The mouse operations can be described in assembly language, or in other languages ​​such as C, C++, etc.
1. Initialize the mouse driver:
For example: Interrupt number INT33h Function 16h Sub-function 17h Interrupt number: used to request service Function number: used to determine which service the user expects to obtain Sub-function number: further specifies the desired service Call register: set the parameters required by the called service function Return register: return the execution result of the service function Calling process: set parameters Interrupt number INT33h Function 15h BX register ES:DX Function 16h Function 17h ES:DX





2. Show or hide the mouse cursor
Functions 1 and 2 of interrupt 33h set the mouse cursor to "on" and "off" respectively. The mouse driver keeps tracking the movement of the mouse and updates its position on the screen when the mouse moves.
The mouse program usually turns the cursor on from the beginning until the end of the program.
The mouse driver uses cursor flags as a hierarchical method of showing and hiding the cursor. The cursor flag is set to -1 when it is first turned on; function 1 adds the flag to 0 to make the cursor appear. Function 2 decrements the flag by 1 and hides the cursor when the flag is negative.

3. Setting the shape of the text mouse cursor
When working in video text mode, the mouse driver generates two types of cursors:
(1) Hardware cursor, which is a regular screen cursor generated by the video hardware and consists of horizontal scan lines.
(2) Software or attribute cursor, in which case the mouse driver writes data at the screen position where the cursor appears. The driver changes the character displayed at this position or changes the character's attributes, making it flash, background color, etc.
(3) Interrupt 33h function Ah sets the type of text cursor: AX stores the function number; BX stores the cursor or software cursor selection; CX stores the starting scan line; DX stores the ending scan line.

4. Set the shape of the graphic mouse cursor

Function 9h of interrupt 33h sets the shape of the mouse cursor in graphics mode and defines a point in the cursor as the hotspot. The cursor consists of a 16 x 16-bit video mask and a 16 x 16-bit cursor mask.

5. Get or set the position of the mouse cursor
Function 4h of interrupt 33h is used to set the position of the mouse cursor, and function 3h is used to report the position of the cursor. AX stores the function number, CX is assigned the X coordinate, and DX is assigned the Y coordinate. P200 Example 7-4

6. Limit the mouse cursor to a part of the screen
The mouse cursor can be limited to a rectangular area on the screen. The horizontal range of the mouse cursor movement is set by the function 7h of interrupt 33h, and the vertical range is set by 8h. P201 Example 7-5

7. Define the screen area where the mouse cursor is not displayed
Function 10h of interrupt 33h defines an area of ​​the screen that will be automatically turned off when the mouse enters the area. When entering, CX stores the left column number of the protected domain, SI stores the right column number; DX stores the first row number, and DI stores the last row number.
Example 7-6 Set a rectangular area ranging from columns 10 to 50 and rows 5 to 30.
MOV AX, 10h; Function number
MOV CX, 10; Left column
MOV SI, 50; Right column
MOV DX, 5; First row
MOV DI, 30; Last row
INT 33h; Call interrupt to set domain

8. Tracking Mouse Movements

Interrupt 33h function Bh reports the actual distance the mouse has moved (measured in meters) since the last call to this function. This function returns the relative horizontal displacement in CX and the relative vertical displacement in DX. Example 7-7 Query the relative displacement of the mouse cursor.
MOV AX, 0Bh
INT 33h
MOV HORZ_MOTION, CX
MOV VERT_MOTION, DX

9. Set the ratio of mouse and cursor movement The program can change the ratio of mouse movement relative to mouse cursor movement. Most mice have a resolution of 200 meters per inch. Moving a certain number of meters in a certain direction translates to one pixel of mouse cursor movement. By default, 8 meters moves one pixel horizontally; 16 meters moves one pixel vertically. Function Fh of interrupt 21h can change the meter-pixel ratio. Function 13h of interrupt 33h changes the threshold that produces double rate. The default value is 64 meters per second. P202 Example 7-8


10. Monitoring Mouse Buttons
Functions 5h and 6h of interrupt 33h report information about the mouse buttons. Both functions return a button status byte in AX reporting the current status of button 2 or 3. This status byte is returned by function 3h of interrupt 21h. It reports the position of the mouse cursor.


Functions 5h and 6h of interrupt 33h keep track of button presses and button releases.

11. Intercepting single click, double click, and drag events
Many programs that use a mouse need to detect single and double clicks of the mouse, and track drag events for button presses.

12. Create a mouse interrupt routine
Create a routine in function Ch of INT 33h. At entry, ES:DX points to a bit pattern stored in the routine CX to set several routine events that should be called. The pattern is:

Keywords:Mouse Reference address:How to operate the mouse

Previous article:Mouse application design
Next article:Keyboard application design

Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号