Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Different Key Movement


Officer Johnson
 Share

Recommended Posts

Hi everyone,

This will be a simple tutorial to teach you how to add movement keys in your game.

If you would like to use different keys then the arrow keys to move this tutorial is useful for that.


This will be all client sided.

Our first step will be to stop the chat box from picking up letter key presses.

To do that we will need to:

In modGeneral, Sub SetFocusOnChat, comment out the part where it sets focus on txtMyChat:
```
'frmMain.txtMyChat.SetFocus
```

Next head over to modGlobals and add:
```
Public Chatting As Boolean
```

Next head over to frmMain find the event "picScreen's MouseDown: add the code:

```
Call SetFocusOnChat
Chatting = False
```

Next on frmMain go to txtMyChat in vb6 use the drop down at the right and select the "click" event. Then input the code:

```
Chatting = True
```

Now is the part where we add in the actual new keys for movement. If you don't want arrow key movement at all in your game you can just delete the arrow key movement code in the sub "CheckInputKeys"

To add the new movement in the sub CheckInputKeys in under the arrow key movement code add:

```
If Chatting = False Then
'Move Up (W)
If GetKeyState(vbKeyW) < 0 Then
DirUp = True
DirDown = False
DirLeft = False
DirRight = False
Exit Sub
Else
DirUp = False
End If

'Move Right (D)
If GetKeyState(vbKeyD) < 0 Then
DirUp = False
DirDown = False
DirLeft = False
DirRight = True
Exit Sub
Else
DirRight = False
End If

'Move down (S)
If GetKeyState(vbKeyS) < 0 Then
DirUp = False
DirDown = True
DirLeft = False
DirRight = False
Exit Sub
Else
DirDown = False
End If

'Move left (A)
If GetKeyState(vbKeyA) < 0 Then
DirUp = False
DirDown = False
DirLeft = True
DirRight = False
Exit Sub
Else
DirLeft = False
End If

End If
```
**For this tutorial purpose i have set the new keys to WASD. But you can use any keys you want on the keyboard just change the appropriate letters in the code we just added.**

That should be it if any questions let me know!
Enjoy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...