e-mods.net

Nod Engine SDK => Scripting and Modifying => Topic started by: GreenDragon on 2013-03-26, 03:56:16

Title: Space = pause?
Post by: GreenDragon 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.
Title: Re: Space = pause?
Post by: Monk Ed 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.
Title: Re: Space = pause?
Post by: Paine 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();
}

}
Title: Re: Space = pause?
Post by: wesclash on 2013-04-09, 07:17:45
Wow, C++ and Java? How would you install that?
Title: Re: Space = pause?
Post by: Monk Ed 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!