GetKey

Pauses for user input of a keyboard key. Pressing the <Esc> key will cancel the operation.

Syntax

Rhino.GetKey ([strMessage])

Parameters

strMessage

Optional.  String.  A prompt or message.

Returns

Array

An array that contains information about the key that was pressed if successful. The array will contain the following:

Element

Description

0

The virtual-key code.  For more information, see Virtual Key Codes.

1

A bit-coded number identifying the state of modifier keys:

Value

Hex

Description

0

&h0

No modifier keys are pressed or toggled.

1

&h1

The <Shift> key is pressed.

2

&h2

The <Control> key is pressed.

4

&h4

The <Alt> key is pressed.

8

&h8

The <Caps Lock> key is on.

16

&h10

The <Num Lock> key is on.

32

&h20

The <Scroll Lock> key is on.

Null

If not successful, or on error.

Example

Sub TestGetKey

  Dim key, shift, ctrl, alt, capslock, numlock, scrllock

  key = Rhino.GetKey("Press a key")

  While Not IsNull(key)

    shift = CBool(key(1) And &h1)

    ctrl = CBool(key(1) And &h2)

    alt = CBool(key(1) And &h4)

    capslock = CBool(key(1) And &h8)

    numlock = CBool(key(1) And &h10)

    scrllock = CBool(key(1) And &h20)

    Call Rhino.Print("Virtual key: " & CStr(key(0)) & ", flags: " & CStr(key(1)))

    Call Rhino.Print("  Chr: " & Chr(key(0)))

    Call Rhino.Print("  Shift: " & CStr(shift))

    Call Rhino.Print("  Ctrl: " & CStr(ctrl))

    Call Rhino.Print("  Alt: " & CStr(alt))

    Call Rhino.Print("  CapsLock: " & CStr(capslock))

    Call Rhino.Print("  NumLock: " & CStr(numlock))

    Call Rhino.Print("  ScrollLock: " & CStr(scrllock))

    key = Rhino.GetKey

  Wend

End Sub

Also See

GetAsyncKeyState

GetString