Yazmaya calıştığım programın bir bolumunde ok tuşlarının vuruşlarını yakalamam gerekiyor. Buraya programın sadece o bolumunu aktardım. Ben bu ok tuşlarını yakalama işini Timer yerine LostFocus'la yapmayı tercih ettim.
Aslında kodlar calışıyor ancak canımı sıkan bir puruz var. İlk 2. vuruşu yanlış icra ediyor, ondan sonraki vuruşları doğru yapıyor. Satır satır defalarca denedim, hep aynı şekilde davranıyor.
Aşağıya adımları yazacağım. Sizden ricam; bu ilk 2. adımı neden yanlış uyguladığı konusunda yardımcı olmanız.
1 - Programı calıştırdıktan sonra ilk vuruşunuz aşağı ok olsun. (Bu ilk vuruşu sadece Command1'in buton rengini değiştirecek şekilde tasarladım. Yani bu ilk aşağı ok bilincli olarak direk Command1'in buton rengini değiştiriyor. Bu vuruşta hata aramayın.) Bu vuruş sonrası Command1 butonu vuruşu yakalayıp buton rengini değiştirecek. Burada sorun yok.
2 - İkinci vuruş sağa ok olsun. Bu vuruş sonrası Command3'un buton renginin değişmesi beklenirken, bir alttaki buton olan Command2'nin buton rengi değişiyor. Bu kısmı debugla defalarca adım adım izledim. Sağ ok tuşladığım halde (VK_Down) kontrolunun icini icra ediyor. Oysaki (VK_Right)'in ici icra edilmeli.
3 - Programı kapatmak icin mouse ile Command5'e click yaptığımda ise 2.nci adımda yapmamış olduğu eylemi icra edip, bir sağ buton olan Comman4'un buton rengini değiştiriyor. Oysaki Command5'in Click olayını gercekleştirmesi gerekir.
Sizlerden bu adımları bu sırayla gozlemlemenizi ve nerede hata yaptığım konusunda yardımlarınızı rica ediyorum.
Formun Gorunuşu :
[IMG]

Module1'in kodları :
Kod:
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Public Const VK_Down = &H28 Public Const VK_Up = &H26 Public Const VK_Left = &H25 Public Const VK_Right = &H27
Form1'in kodları :
Kod:
Dim ActiveButon As String Private Sub Form_Load() Me.Show ActiveButon = "Any" Command1.SetFocus End Sub Private Sub Command5_Click() End End Sub Private Sub Command1_LostFocus() If Command5.Default = True Then Exit Sub End If If ActiveButon = "Any" Then Command1.BackColor = &HC0E0FF Command1.Default = False Command1.SetFocus ActiveButon = "Command1" Exit Sub End If If ActiveButon = "Command1" Then If GetAsyncKeyState(VK_Down) Then Command1.BackColor = &H8000000F Command1.Default = False Command2.BackColor = &HC0E0FF Command2.Default = True Command2.SetFocus ActiveButon = "Command2" Else If GetAsyncKeyState(VK_Up) Then Command1.BackColor = &H8000000F Command1.Default = False Command2.BackColor = &HC0E0FF Command2.Default = True Command2.SetFocus ActiveButon = "Command2" Else If GetAsyncKeyState(VK_Left) Then Command1.BackColor = &H8000000F Command1.Default = False Command3.BackColor = &HC0E0FF Command3.Default = True Command3.SetFocus ActiveButon = "Command3" Else If GetAsyncKeyState(VK_Right) Then Command1.BackColor = &H8000000F Command1.Default = False Command3.BackColor = &HC0E0FF Command3.Default = True Command3.SetFocus ActiveButon = "Command3" End If End If End If End If End If End Sub Private Sub Command2_LostFocus() If Command5.Default = True Then Exit Sub End If If ActiveButon = "Command2" Then If GetAsyncKeyState(VK_Down) Then Command2.BackColor = &H8000000F Command2.Default = False Command1.BackColor = &HC0E0FF Command1.Default = True Command1.SetFocus ActiveButon = "Command1" Else If GetAsyncKeyState(VK_Up) Then Command2.BackColor = &H8000000F Command2.Default = False Command1.BackColor = &HC0E0FF Command1.Default = True Command1.SetFocus ActiveButon = "Command1" Else If GetAsyncKeyState(VK_Left) Then Command2.BackColor = &H8000000F Command2.Default = False Command4.BackColor = &HC0E0FF Command4.Default = True Command4.SetFocus ActiveButon = "Command4" Else If GetAsyncKeyState(VK_Right) Then Command2.BackColor = &H8000000F Command2.Default = False Command4.BackColor = &HC0E0FF Command4.Default = True Command4.SetFocus ActiveButon = "Command4" End If End If End If End If End If End Sub Private Sub Command3_LostFocus() If Command5.Default = True Then Exit Sub End If If ActiveButon = "Command3" Then If GetAsyncKeyState(VK_Down) Then Command3.BackColor = &H8000000F Command3.Default = False Command4.BackColor = &HC0E0FF Command4.Default = True Command4.SetFocus ActiveButon = "Command4" Else If GetAsyncKeyState(VK_Up) Then Command3.BackColor = &H8000000F Command3.Default = False Command4.BackColor = &HC0E0FF Command4.Default = True Command4.SetFocus ActiveButon = "Command4" Else If GetAsyncKeyState(VK_Left) Then Command3.BackColor = &H8000000F Command3.Default = False Command1.BackColor = &HC0E0FF Command1.Default = True Command1.SetFocus ActiveButon = "Command1" Else If GetAsyncKeyState(VK_Right) Then Command3.BackColor = &H8000000F Command3.Default = False Command1.BackColor = &HC0E0FF Command1.Default = True Command1.SetFocus ActiveButon = "Command1" End If End If End If End If End If End Sub Private Sub Command4_LostFocus() If Command5.Default = True Then Exit Sub End If If ActiveButon = "Command4" Then If GetAsyncKeyState(VK_Down) Then Command4.BackColor = &H8000000F Command4.Default = False Command3.BackColor = &HC0E0FF Command3.Default = True Command3.SetFocus ActiveButon = "Command3" Else If GetAsyncKeyState(VK_Up) Then Command4.BackColor = &H8000000F Command4.Default = False Command3.BackColor = &HC0E0FF Command3.Default = True Command3.SetFocus ActiveButon = "Command3" Else If GetAsyncKeyState(VK_Left) Then Command4.BackColor = &H8000000F Command4.Default = False Command2.BackColor = &HC0E0FF Command2.Default = True Command2.SetFocus ActiveButon = "Command2" Else If GetAsyncKeyState(VK_Right) Then Command4.BackColor = &H8000000F Command4.Default = False Command2.BackColor = &HC0E0FF Command2.Default = True Command2.SetFocus ActiveButon = "Command2" End If End If End If End If End If End Sub
__________________