MouseK (Property), MouseKB Function

Purpose

Returns the current status of the mouse buttons and shift keys.

Syntax

mk% = [Screen.]MouseK

ms% = MouseKB

mk%, ms%:ivar

Description

The MouseK function returns the status of the mouse buttons.

1 - Left button pressed

2 - Right button pressed

3 - Both pressed

The MouseKB function returns the current status of the shift keys of your keyboard.

1 - Left and/or Right Shift

2 - Left and/or Right Ctrl

4 - Left Alt key

6 - Right Alt key

Example

OpenW 1

Local a$

a$ = "please press Shift key + mousekey"

TitleW 1, a$

PrintScroll = True

Do

Do

Loop Until MouseK

Print MouseK, MouseKB

Print "to end with mouse + Escape-key"

Loop Until GetAsyncKeyState(27) < 0

CloseW 1

Remarks

MouseKB uses the GetAsyncKeyState() API function.

Known Issues

Pressing the right Alt key is the same as pressing Ctrl and the left Alt key so the two key combinations can not be told apart using MouseKB. To get a more accurate result use the Screen.ShiftKeys value.


Pressing the right Alt key, on occasions either a 2 or 4 will be returned by MouseKB rather than or as well as the expected 6. This can seen by running the example below and contunally pressing the right Alt key.

Local Int mk, ms, oms

Debug.Show

Do

mk = MouseK

ms = MouseKB

If ms = 0 : oms = 0

ElseIf ms <> 0 And ms <> oms : Debug ms;" - "; : oms = ms

If ms >= 6 Then Debug.Print "Right Alt key"; : Xor ms, 6 : If ms <> 0 Then Debug.Print " & ";

If Btst(ms, 0) Then Debug.Print "Shift key"; : If ms <> 1 Then Debug.Print " & "; : Xor ms, 1

If Btst(ms, 1) Then Debug.Print "Ctrl key"; : If ms <> 2 Then Debug.Print " & "; : Xor ms, 2

If Btst(ms, 2) Then Debug.Print "Left Alt key";

Debug.Print

EndIf

Loop Until mk <> 0

Debug.Hide

To get around this problem, use the Screen.ShiftKeys value.

See Also

Screen, Mouse, MouseX, MouseSY

{Created by Sjouke Hamstra; Last updated: 19/10/2014 by James Gaite}