Results 1 to 2 of 2

Thread: Arrow keys on the keyboard

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    treehouse
    Posts
    106

    Question

    I am using the MSFlexgrid and I am trying to capture the Keycode when the user hits the arrow keys on the keyboard but I notice that when the keys are used it does not fire the KeyPress or the KeyDown Events and I am not sure how to capture those keys. I also tried the LeaveCell() event also but I am not able to capture the event.

    Here is a sample of my code:
    for some reason it will not capture the keydown code.


    Private Sub MSFlexGrid1_LeaveCell()
    Dim KeyAscii As Integer

    If Not MSFlexGrid1.Text > CStr(0) Then
    MSFlexGrid1.Text = ""
    End If
    MSFlexGrid1 = Format$(MSFlexGrid1, "0.00") 'or whatever format
    MSFlexGrid1.CellBackColor = &H80000005 'white
    Select Case KeyAscii
    Case vbKeyDown
    With MSFlexGrid1
    mlCellLeft = .CellLeft
    mlCellTop = .CellTop
    mlCellWidth = .CellWidth
    mlCellHeight = .CellHeight
    VScroll1.Visible = True
    VScroll1.Left = mlCellLeft + 1480
    VScroll1.Height = mlCellHeight
    VScroll1.Top = mlCellTop + .Top + 20
    End With
    End Select
    End Sub

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Well you declare KeyAscii as an integer in the event but you never give it a value so in the Select Case statement KeyAscii will be zero.
    Try this instead:
    Code:
    Private Declare Function GetAsyncKeyState _
     Lib "user32" ( _
     ByVal vKey As Long) As Integer
    
    Private Sub MSFlexGrid1_LeaveCell()
        If Not MSFlexGrid1.Text > CStr(0) Then
            MSFlexGrid1.Text = ""
        End If
        MSFlexGrid1 = Format$(MSFlexGrid1, "0.00") 'or whatever format
        MSFlexGrid1.CellBackColor = &H80000005 'white
        If GetAsyncKeyState(vbKeyDown) Then
            With MSFlexGrid1
                mlCellLeft = .CellLeft
                mlCellTop = .CellTop
                mlCellWidth = .CellWidth
                mlCellHeight = .CellHeight
                VScroll1.Visible = True
                VScroll1.Left = mlCellLeft + 1480
                VScroll1.Height = mlCellHeight
                VScroll1.Top = mlCellTop + .Top + 20
            End With
        End If
    End Sub
    Good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width