Please Help Support E-Mods.net by Donating

e-mods.net

  • 2017-09-19, 12:04:33
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search

News:

Looking for VTMR Modding Tutorials? Check out the Open Nod Development section of e-mods.net.

Author Topic: Space = pause?  (Read 1652 times)

GreenDragon

  • Member
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 52
Space = pause?
« on: 2013-03-26, 03:56:16 »

Is it possible to assign the Space bar as the Pause button using some kind of modification? I play on a laptop and have to press two buttons at different ends of the keyboard which is a bit awkward.
Logged

Monk Ed

  • Member
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 4
Re: Space = pause?
« Reply #1 on: 2013-03-31, 19:53:35 »

Is it possible to assign the Space bar as the Pause button using some kind of modification? I play on a laptop and have to press two buttons at different ends of the keyboard which is a bit awkward.
On Planet Vampire I found a mod in the Scripts section (I think) called something like "KeyboardTest" which was provided as an example of a script that could read keyboard input. It was used to make your character walk using the keyboard (forward with the up key, turn left/right with the left/right keys). Only problem is, it didn't come with any source code! But this at least indicates that it's possible.
Logged

Paine

  • Member
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 23
Re: Space = pause?
« Reply #2 on: 2013-04-04, 00:34:50 »

Is it possible to assign the Space bar as the Pause button using some kind of modification? I play on a laptop and have to press two buttons at different ends of the keyboard which is a bit awkward.
On Planet Vampire I found a mod in the Scripts section (I think) called something like "KeyboardTest" which was provided as an example of a script that could read keyboard input. It was used to make your character walk using the keyboard (forward with the up key, turn left/right with the left/right keys). Only problem is, it didn't come with any source code! But this at least indicates that it's possible.

Here's the source:

Code: [Select]
#include <stdio.h>

#include <windows.h>
#include <winuser.h>

#define FILENAME "keylog.txt"

void CheckKey(int key);

LRESULT CALLBACK KeyboardHook(

int nCode, // hook code

WPARAM wParam, // message identifier

LPARAM lParam // pointer to structure with message data

);


HHOOK hHook;

int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow )
{
    hHook = SetWindowsHookEx(13, KeyboardHook, hInstance , 0);

    while (GetMessage(NULL,NULL,0,0)) ; // NOP while not WM_QUIT

    return UnhookWindowsHookEx(hHook);
}

LRESULT CALLBACK KeyboardHook (int nCode, WPARAM wParam, LPARAM lParam )
{
    if (nCode == HC_ACTION)
    {

        if (wParam == WM_SYSKEYDOWN || wParam == WM_KEYDOWN)
        {
            CheckKey (((PKBDLLHOOKSTRUCT)lParam)->vkCode);
        }
        return CallNextHookEx(hHook, nCode, wParam, lParam);
    }
}
void CheckKey(int key)
{

    int windowTitleLength = GetWindowTextLengthW(GetForegroundWindow());
    char windowTitle[windowTitleLength];
    GetWindowText(GetForegroundWindow(),windowTitle,windowTitleLength + 1);

    if(strcmp(windowTitle, "Vampire") == 0 && (key == VK_LEFT || key == VK_UP || key == VK_RIGHT))
    {
        char *zFilename;

        if(key == VK_LEFT)
        {
            zFilename = "Keys\\left";
        }
        else if(key == VK_RIGHT)
        {
            zFilename = "Keys\\right";
        }
        else
        {
            zFilename = "Keys\\up";
        }

        FILE *pfile = fopen(zFilename, "a+");
        fwrite(windowTitle, 1, sizeof(windowTitle), pfile);
        fclose(pfile);
    }

}

Code: [Select]
import java.io.File;

public class EffectKBTest extends Codex
{
String files[] = { "left", "right"};
int actorGuid;
float prevOri[] = new float[3];

public void effectstarted(int actorGuid, int effectGuid, int creatorGuid, int duration)
{
CodexConsole.Print(0,1,"KB Effect Added.");
this.actorGuid = actorGuid;
SetTimer(0F,1);
}

public void timer(int timerID, float arg0, float arg1, float arg2, float arg3)
{
File file = new File("KeyboardTest\\Keys\\up");
if(file.exists())
{
if(!file.delete())
CodexConsole.Print(0,1,"Failed to delete");
CodexActor actor = new CodexActor(actorGuid);
float pos[] = actor.GetPosition();
float ori[] = actor.GetOrientation();
float angle = ori[2] + 90;

pos[0] += (float)(Math.cos((double)angle * (Math.PI / 180)) * 75);
pos[1] += (float)(Math.sin((double)angle * (Math.PI / 180)) * 75);

float zPos = pos[2];

for(int i = -32; i < 32; i+=16)
{
pos[2] = zPos + i;
if(actor.SendActorToPos(pos, actor.GetActorWalkSpeed()) == true)
{
break;
}
else
{
pos[2] = zPos;
}
}
CodexConsole.Print(0,1,"moving");
}

for(int i = 0; i < files.length; i++)
{
file = new File("KeyboardTest\\Keys\\" + files[i]);
if(file.exists())
{
if(!file.delete())
CodexConsole.Print(0,1,"Failed to delete");
CodexActor actor = new CodexActor(actorGuid);
actor.Stop();
float ori[] = actor.GetOrientation();
if(prevOri[0] != 0)
{
if(ori[0] != prevOri[0])
ori[0] = prevOri[0];
if(ori[1] != prevOri[1])
ori[1] = prevOri[1];
}
else
prevOri = ori;
ori[2] += (45 - (i * 90));
actor.SetOrientation(ori);
}
}
SetTimer(0.1F, 1);
}


public void effectended(int actorGuid, int effectGuid, int creatorGuid, int reason)
{
EndEffect();
}

public void killed(int guid, int causeID, int captureID)
{
EndEffect();
}

public void EndEffect()
{
KillAllTimers();
}

}
Logged

wesclash

  • Member
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 60
Re: Space = pause?
« Reply #3 on: 2013-04-09, 07:17:45 »

Wow, C++ and Java? How would you install that?
Logged

Monk Ed

  • Member
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 4
Re: Space = pause?
« Reply #4 on: 2013-04-13, 14:01:21 »

Whoa. So the C++ file reads keyboard input from the Vampire window and creates files on the filesystem when the desired keys are pressed, and then the Java file reads the file system and if those files exist then it knows you've pressed those keys.

I can only imagine that interpreting keyboard input via the creation of files on the hard drive must be fraught with all kinds of potential problems that could affect the responsiveness of such controls.

Thanks for this!
Logged
 

Page created in 0.057 seconds with 19 queries.