Mirage Source
[FEATURE] Lock Movement on Tab - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51)
+----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44)
+------ Forum: Tutorials (https://mirage-engine.uk/forums/forumdisplay.php?fid=13)
+------ Thread: [FEATURE] Lock Movement on Tab (/showthread.php?tid=2162)



[FEATURE] Lock Movement on Tab - JokeofWeek - 22-09-2008

Alright, so this is a pretty simple feature. It's basically like a Caps Lock, except instead of Caps, you run Tongue

Difficulty : 1 / 5

ModGlobals

In modGlobals, look for

Code:
' Game direction vars

And in that little section, add :
Code:
Public IsUserTabbed As Boolean
.

In modConstants, look for :
Code:
Public Const VK_CONTROL As Long = &H11

And under it add :
Code:
Public Const VK_TAB as long = &H9

Now, in modGameLogic, look for sub GameLoop. Add the following variable at the top, inside that sub :

Code:
Dim TabTimer as long

and then look for the following snippet :

Code:
If GetAsyncKeyState(VK_CONTROL) >= 0 Then
            If ControlDown = True Then
            ControlDown = False
            End If
        End If

and add this under :

Code:
If GetAsyncKeyState(VK_TAB)  0 Then
            If TabTimer + 1000 < GetTickCount Then
                IsUserTabbed = Not IsUserTabbed
                TabTimer = GetTickCount
            End If
        End If

Now, what this code does is, each time you press tab, it will turn the IsUserTabbed boolean on and off, so you just have to press it once and it'll turn on Smile. The reason for the TabTimer is because, with that function, it is processed very quickly, and if you hold tab it will mess up. You cannot do this with the CheckInput sub because the Tab key code is basically 'removed' by VB6 since you use tab to go through controls.

Now, in modGameLogic, look for sub CheckMovement. Now, look at the part that says :

Code:
' Check if player has the shift key down for running
            If ShiftDown Then
                Player(MyIndex).Moving = MOVING_RUNNING
            Else
                Player(MyIndex).Moving = MOVING_WALKING
            End If

And replace it with :

Code:
' Check if player has the shift key down for running
            If ShiftDown Or IsUserTabbed Then
                Player(MyIndex).Moving = MOVING_RUNNING
            Else
                Player(MyIndex).Moving = MOVING_WALKING
            End If

This will check whether you are pressing shift or you pressed tab to turn on the Auto-Run Smile And there you go, wasn't that simple? Big Grin


Re: [FEATURE] Lock Movement on Tab - Nean - 22-09-2008

Didn't work for me. I press tab, but it doesn't do anything. Maybe I did the tut wrong.


Re: [FEATURE] Lock Movement on Tab - JokeofWeek - 22-09-2008

Sorry about that, updated it now Big Grin


Re: [FEATURE] Lock Movement on Tab - Nean - 22-09-2008

Works now. Awesome job dude.


Re: [FEATURE] Lock Movement on Tab - skillzalot - 22-09-2008

I added this feature into my client good job.


Re: [FEATURE] Lock Movement on Tab - Kousaten - 22-09-2008

Dude nice. Big Grin This will save people like me who suffer from carpal tunnel. Lets us not hold a key down all day when it already hurts to type a lot.


Re: [FEATURE] Lock Movement on Tab - Mattyw - 22-09-2008

Kind of an off/on-topic note:

Code:
Public Const VK_CONTROL As Long = &H11

how do you get the &H11? Just make it up?


Re: [FEATURE] Lock Movement on Tab - Jacob - 22-09-2008

I found this snippet of code awhile ago:

Code:
' Used so we can actually use the tab key ingame
    For i = 0 To Controls.Count - 1
       Controls(i).TabStop = False
       ' Has to be used for controls that don't have tabstop
       On Error Resume Next
    Next

This will allow you use tabkey without any problems. It would get added Form_Load().


Re: [FEATURE] Lock Movement on Tab - JokeofWeek - 22-09-2008

Mattyw Wrote:Kind of an off/on-topic note:

Code:
Public Const VK_CONTROL As Long = &H11

how do you get the &H11? Just make it up?

Nah, &H11 is the hexadecimal value for that Key Wink

Dugor Wrote:I found this snippet of code awhile ago:

Code:
' Used so we can actually use the tab key ingame
    For i = 0 To Controls.Count - 1
       Controls(i).TabStop = False
       ' Has to be used for controls that don't have tabstop
       On Error Resume Next
    Next

This will allow you use tabkey without any problems. It would get added Form_Load().

Ah nice, I modify it to use that Smile Thanks mate =]


Re: [FEATURE] Lock Movement on Tab - Mattyw - 22-09-2008

JokeofWeek Wrote:
Mattyw Wrote:Kind of an off/on-topic note:

Code:
Public Const VK_CONTROL As Long = &H11

how do you get the &H11? Just make it up?

Nah, &H11 is the hexadecimal value for that Key Wink

Dugor Wrote:I found this snippet of code awhile ago:

Code:
' Used so we can actually use the tab key ingame
    For i = 0 To Controls.Count - 1
       Controls(i).TabStop = False
       ' Has to be used for controls that don't have tabstop
       On Error Resume Next
    Next

This will allow you use tabkey without any problems. It would get added Form_Load().

Ah nice, I modify it to use that Smile Thanks mate =]

So how do I find the Hex value of keys. :S


Re: [FEATURE] Lock Movement on Tab - GIAKEN - 22-09-2008

Google them.