hi everyone, i'd been creating a tic tac toe game using VB 6.0 and it is working perfectly. And now i have to create a form which allow user to only uses keyboard to control the position of their choices instead of using click() command by mouse. Any method to do that? i am still new in learning VB 6.0. Hopefully i can get help from you guys.
P/S: Using the four direction keys from the keyboard to let the user choose the position and a enter for confirmation or enter the data.

Recommended Answers

All 4 Replies

Its easy...
get the key strokes like this and do...

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyUp Then
 ' move up
ElseIf KeyAscii = vbKeyDown Then
 'move down
ElseIf KeyAscii = vbKeyRight Then
 'move right
ElseIf KeyAscii = vbKeyLeft Then
 'move left
End Sub

askB

You can also assign individual keys for each of the positions using the above logic.

well, thanks for the contribution, however it doesnt seems to work...
tic tac toe game has 9 squares, if the user can control the position of each of the square using keyboard. I'd tried to load a mouse event class module and create another form with have the directions buttons and a confirmation command. Both are connected using port. However it seems doesnt work as well. Any function to replace this?
Below is the little code for my keyboard event:

Private m_Mouse As CMouseEvent
Private m_oX As Long
Private m_oY As Long
Private Sub Form_Load()
'Setting up default state of
'all variables.

'Makes all squares clear
Dim Index As Integer
'intialize of mouse module
Set m_Mouse = New CMouseEvent
m_Mouse.MoveTo 550, 550
m_oX = 550
m_oY = 550

Private Sub Timer1_Timer()
If HumanMovedAlready = True Then Form1.MousePointer = 2
If CompMovedAlready = True Then Form1.MousePointer = 12

'If MSComm1.InBufferCount > 0 Then
    'Mystring = MSComm1.Input
    If Mystring = "l" Then
        m_oX = m_oX - 10
        m_Mouse.MoveTo m_oX, m_oY
    ElseIf Mystring = "r" Then
        m_oX = m_oX + 10
        m_Mouse.MoveTo m_oX, m_oY
    ElseIf Mystring = "u" Then
         m_oY = m_oY - 10
        m_Mouse.MoveTo m_oX, m_oY
    ElseIf Mystring = "d" Then
         m_oY = m_oY + 10
        m_Mouse.MoveTo m_oX, m_oY
    ElseIf Mystring = "c" Then
    m_Mouse.Click
    End If

End If
End Sub

thanks for anyone that help...thanks

Can you please specify which control you are using for designing the 9 boxes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.