The (static) class Mouse (gb.qt4) is used to retrieve information about the mouse and defines constants for the shape of the mouse pointer. In addition to the properties, this class has only 2 methods. The class Mouse has no events!
Only selected mouse properties are presented in the following table, because essential information about the mouse wheel (MouseWheel) is described in → chapter 14.2.3 Mouse Wheel - MouseWheel.
Property | Description |
---|---|
Alt | Returns True if ALT key is pressed |
Control | Returns True if the Control key has been pressed |
Shift | Returns True if the SHIFT key is pressed |
Left | Returns True if the left mouse button is pressed |
Middle | Returns True if the middle mouse button is pressed |
Right | Returns True if the right mouse button is pressed |
X | Returns the relative horizontal position of the mouse cursor (integer value) |
Y | Returns the relative vertical position of the mouse cursor (integer value) |
Meta | Returns True if the Meta or Super key has been pressed |
Forward | Returns True if the mouse wheel is turned forward |
Table 14.2.1.1.1: Description of selected properties of the 'Mouse' class
The Mouse.Inside method returns True when the mouse pointer is over the specified component:
Static Function Inside ( Control As Control ) As Boolean
The Mouse.Move method moves the mouse pointer to the defined xy position on the screen:
Static Sub Move ( X As Integer, Y As Integer )
Mouse pointers are always bound to components. Gambas has a set of defined mouse pointers and provides constants with sufficient self-explanatory names for these mouse pointers:
Arrow Blank Cross Custom Default Horizontal Pointing SizeAll SizeE SizeH SizeN SizeNE SizeNESW SizeNW SizeNWSE SizeS SizeSE SizeSW SizeV SizeW SplitH SplitV Text Vertical Wait
The following constants are particularly important: Mouse.Blank, Mouse.Default, Mouse.Wait and for using your own mouse cursor Mouse.Custom.
txtValue.Mouse = Mouse.Blank ' The Text Field component does not have a mouse pointer
' The default mouse pointer is replaced by your own existing mouse pointer DrawingArea1.Mouse = Mouse.Custom DrawingArea1.Cursor = New Cursor(Picture["icon:/16/pen"], 0, 15)
Alternatively, you can call the image editor in the Gambas IDE and draw your own mouse pointers and use them for your own projects:
In the following procedure, the mouse pointer of the form FMain is switched from the standard mouse pointer Mouse.Arrow to Mouse. Wait and after the output of the command 'ping' is changed back to the standard mouse pointer Mouse.Arrow.
Public Sub btnPingOverShell_Click() Dim sCommand As String SetLEDColor("green") TextArea.Clear FMain.Mouse = Mouse.Wait Wait sCommand = "ping" & Chr(32) & TextBox1.Text & " -c 4" Shell sCommand To TextArea.Text TextArea.Text = gb.newline & TextArea.Text Wait FMain.Mouse = Mouse.Default SetLEDColor("orange") End ' PingOverShell
This part of the source code belongs to a program with a window without window line, which can still be moved comfortably. The specified procedures use the properties Mouse.Left, Mouse.X and Mouse.Y:
' Gambas class file ' Context menu to exit the program! PUBLIC iDeltaX AS Integer PUBLIC iDeltaY AS Integer PUBLIC SUB Form_Open() FMain.Center END ' Form_Open() PUBLIC SUB Form_MouseDown() IF Mouse.Left THEN iDeltaX = Mouse.X iDeltaY = Mouse.Y ENDIF ' Mouse.Left ? END PUBLIC SUB Form_MouseMove() IF Mouse.Left THEN FMain.Move(FMain.X - iDeltaX + Mouse.X, FMain.Y - iDeltaY + Mouse.Y) ENDIF ' Left mouse button pressed during mouse movement? END ' Form_MouseMove()
Hints:
Mouse is the property of a component that is only viewed in conjunction with the mouse pointer. It indicates which mouse pointer is to be used - either a mouse pointer from the collection of gambas or a mouse pointer of your own:
FMain.Mouse = Mouse.Wait sCommand = sProgramName & Chr(32) & TextBox1.Text & " -c 4" Shell sCommand To TextArea.Text TextArea.Text = gb.newline & TextArea.Text FMain.Mouse = Mouse.Default
Even if the class Mouse itself does not have mouse events, there are events in the classes for certain components that refer to the mouse. These events are dealt with in chapter 14.2.2.2.