KEYPRESS function

Purpose: KEYPRESS returns a value corresponding to the key combination pressed.


 Syntax 1:

 RetVal% = KEYPRESS

 Parameters:

  • RetVal%
    • For alphanumeric and CTRL-alpha keys, KEYPRESS returns the ASCII code value of the character corresponding to the key pressed.
    • Alt + alphanumeric keys return Scancode + 1000.
    • Alt + enhanced keys return(Scancode + 1000) * -1.
    • Ctrl + enhanced keys return(Scancode + 2000) * -1.

Note : KEYPRESS waits for keyboard input but does not automatically echo to the screen. Because mouse and keyboard handlers are tied together in Windows, Keypress will return values when the mouse is moving over an active window.

Example:

The GUI snippet below shows how to capture a keypress.

 
 GUI "GetKey"
 
 SUB FORMLOAD
   GLOBAL Form1 AS HWND
   Form1 = BCX_FORM("BCX_TEMPLATE", 0, 0, 110, 110)
   BCX_SET_FORM_COLOR(Form1,QBCOLOR(31))
   CENTER(Form1)
   SHOW(Form1)
 END SUB
 
 BEGIN EVENTS
   SELECT CASE CBMSG
   CASE WM_GETDLGCODE
     FUNCTION=DLGC_WANTALLKEYS
   CASE WM_KEYDOWN
     SELECT CASE wParam
     CASE VK_HOME
       MSGBOX "VK_HOME"
     CASE VK_END
       MSGBOX "VK_END"
     CASE VK_NEXT
       MSGBOX "VK_NEXT"
     CASE VK_PRIOR
       MSGBOX "VK_PRIOR"
     CASE VK_DOWN
       MSGBOX "VK_DOWN"
     CASE VK_UP
       MSGBOX "VK_UP"
     CASE VK_LEFT
       MSGBOX "VK_LEFT"
     CASE VK_RIGHT
       MSGBOX "VK_RIGHT"
     CASE VK_RETURN
       MSGBOX "VK_RETURN"
     END SELECT
   END SELECT
 END EVENTS
 

BCX Console Sample Programs using KEYPRESS function.

S75.bas   S90.bas