Monitoring Mouse Activity

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Monitoring Mouse Activity:

There are three fundamental mouse event procedures:


Name Event
Mouse Down user clicks one of the mouse buttons
Mouse up user releases a mouse button
Mouse move users move the mouse pointer to a control or to a blank
area of the form.

 Controls recognize a mouse event only when the mouse pointer is inside is inside the control.
 All Mouse Event procedures take the same form and use the same parameter

ObjectName_MouseEvent(Button As Integer, Shift As Integer, X As Single ,Y As single)


Eg:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)


Circle (X, Y), 75
End Sub

 This simple event procedure usese the positioning information passed by X and Y
 Each time you click a mouse button, a small circle is centered exactly where you clicked

Eg:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)


Dim Ccode As Integer
Randomize
Ccode = Int(15 * Rnd)
FillStyle = 0
FillColor = QBColor(Ccode)
Circle (X, Y), 75
End Sub
Using the Button Argument:

The button argument uses the lowest three bits of value of the integer,

Button Constant Value


Left Vbleft Button 1
Right Vbright Button 2
Middle Vbmiddle Button 4

 To work mouse button to perform different task for each button button arguments are used
 Clicking Right mouse button performs different action and Left mouse button performs
different action

Eg:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Ccode As Integer
Randomize
Ccode = Int(15 * Rnd)
Select Case Button
Case vbLeftButton
Circle (X, Y), 75, QBColor(Ccode)
FillColor = &HFFFFFF
Case vbRightButton
FillStyle = 0
FillColor = QBColor(Ccode)
Circle (X, Y), 75
End Select
End Sub
COMBINING THE KEYBOARD AND MOUSE:

ACTION CONSTANT BIT SET AND VALUE


Shift key down Vbshift mask Bit:0 value=1
CTRL key down Vbctrl mask Bit 1:value=2
ALT key down Vbalt mask Bit 2:value=4
Shift+CTRL keys down Vb shiftmask+vbctrlmask Bits 0;value=3
Shift+alt keys down Vbshiftmask+vbAltmask Bit 0 & 2;value=5
At the present time, most people seem to be writing code for the SHIFT key by using a select case
statement as follows:

Select case shift this is the shift parameter in the mouse event

‘Procedure not the shift key’

Case vbshift mask=1


Print “you pressed the shift key”
Case vbctrlmask =2
Print “You pressed the ctrl key.”
Case vbshiftmask+vbaltmask=3
Print “You pressed the shift +ALt keys”
Case vbAltmask=4
Print” You pressed the alt key”
End select

MOUSE MOVE EVENT:

Visual Basic calls the mouse move event procedure whenever the user moves the mouse.

This is the most powerful of the mouse event procedure because you can analyse completely
the state of mouse buttons.

Button Constant Value


Left button Vbleftbutton 1
Right button Vbrightbutton 2
Middle button Vbmiddlebutton 4
Left+right Vb leftbutton+vbrightbutton 3
Left+middle Vbleftbutton+vbmiddlebutton 5
Right+middle Vbrightbutton+vbmiddlebutto 6
n
Eg:

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)


DrawWidth = 6
PSet (X, Y)
End Sub
 This simple mousemove event procedure draws small circles along the path of the mouse
movement when the mouse is moved inside the Form.
 circles are widely spaced when the mouse is moved quickly and closely spaced when the
mouse is moved slowly.

Dragging and dropping operations for controls:

Controls permit two types of dragging.

 Manual Dragging
 Automatic Dragging
 These correspond to two different values of the drag mode property.

Item Description
Dragmode property Allows automatic dragging or manual dragging
Dragicon property Set this to change from the gray rectangle to a
actual icon. When dragging.
Dragdropevent Associated with the target of the operation.
Dragover event Associated with any control the source control
passing over when dragging.
Drag method Starts or stops dragging. When dragmode is set
to manual.

Manual dragging:

 In manual dragging for every special circumstances the user needs to write the codes
 The syntax for this method is control. Drag TypeOfAction.

The typeofaction is an integer value is:

Control.drag 0 Cancel dragging


Control.drag 1 Begin dragging
Control.drag 2 Drop the control
Automatic Dragging:

 In automatic dragging the user may drag the control around the project
 The drag mode property value for automatic dragging is 1

You might also like