#include <windows.h>
#include <stdio.h>
staticconstint guide_button_value = 0x0400;
/* the secret function outputs a different struct than the official GetState. */
typedefstruct
{
unsignedlong eventCount;
WORD wButtons;
BYTE bLeftTrigger;
BYTE bRightTrigger;
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
} XINPUT_GAMEPAD_SECRET;
int(__stdcall *secret_get_gamepad) (int, XINPUT_GAMEPAD_SECRET*);
int main(int argc, char** argv)
{
TCHAR xinput_dll_path[MAX_PATH];
GetSystemDirectory(xinput_dll_path, sizeof(xinput_dll_path));
strcat(xinput_dll_path, "\\xinput1_3.dll");
HINSTANCE xinput_dll = LoadLibrary(xinput_dll_path);
secret_get_gamepad = GetProcAddress(xinput_dll, (LPCSTR)100); // load ordinal 100
XINPUT_GAMEPAD_SECRET pad1;
for(;;) // loop
{
secret_get_gamepad(0, &pad1);
if (pad1.wButtons & guide_button_value)
{
printf("button pressed");
return 0;
}
Sleep(33);
}
return 0;
}
But I wanted to detect if it's held down for 3 second before do my printf
After many search, I'm pretty lost.
The usual solution is to detect if the button is pressed and if it's realeased but I can't use ximputgetstate or regular getstate (or I haven't successfully done it)
My c/c++ knowledge is pretty outdated (ingeneer school 20 years ago) so if someone have a idea :)
thank you very much :)
I integrated it to my code but when I tried to compile it I got errors, I integrated Iostream and tried for instance DWORD oldtime = GetTickCount;
but nothing worked.
here is my modified code (I added comments),
#include <windows.h>
#include <stdio.h>
#include <iostream>
staticconstint guide_button_value = 0x0400;
/* the secret function outputs a different struct than the official GetState. */
typedefstruct
{
unsignedlong eventCount;
WORD wButtons;
BYTE bLeftTrigger;
BYTE bRightTrigger;
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
} XINPUT_GAMEPAD_SECRET;
int(__stdcall *secret_get_gamepad) (int, XINPUT_GAMEPAD_SECRET*);
int main(int argc, char** argv)
{
TCHAR xinput_dll_path[MAX_PATH];
GetSystemDirectory(xinput_dll_path, sizeof(xinput_dll_path));
strcat(xinput_dll_path, "\\xinput1_3.dll");
HINSTANCE xinput_dll = LoadLibrary(xinput_dll_path);
secret_get_gamepad = GetProcAddress(xinput_dll, (LPCSTR)100);
XINPUT_GAMEPAD_SECRET pad1;
for(;;) // loop
{
secret_get_gamepad(0, &pad1);
oldtime = GetTickCount; //get the time the button is pressed
while (pad1.wButtons & guide_button_value)
{
newtime = GetTickCount(); //get the time the button is released
if (newtime - oldtime > 3000) //if the time between press and release is 3sec or more
{
printf("button pressed");
return 0;
}
Sleep(33);
}
return 0;
}
}
when I try to compile:
1 2 3 4
D:\Mes Documents\Sources\Guide held .cpp In function 'int main(int, char**)'::
61 D:\Mes Documents\Sources\Guide held .cpp:30 invalid conversion from 'FARPROC {aka int (*)()}' to 'int (*)(int, XINPUT_GAMEPAD_SECRET*) {aka int (*)(int, XINPUT_GAMEPAD_SECRET*)}' [-fpermissive]
4 D:\Mes Documents\Sources\Guide held .cpp:39 'oldtime' was not declared in this scope
5 D:\Mes Documents\Sources\Guide held .cpp:43 'newtime' was not declared in this scope