Detect if xbox 360 guide button on pc is held down

Hi,

I made this (found the trick on the net)that allow to use the guide button of a 360 pad. I use wxdevc++.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <windows.h>
#include <stdio.h>

static const int guide_button_value = 0x0400;

/* the secret function outputs a different struct than the official GetState. */
typedef struct 
{
    unsigned long 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 :)
Something like this maybe:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
while (1)
{
	if (pad1.wButtons & guide_button_value)
	{
		oldtime = GetTickCount;
		
		while (pad1.wButtons & guide_button_value)
		{
			newtime = GetTickCount();
			
			if (newtime - oldtime > 3000)
			{
				printf(...);
				return 0;
			}
		}
	}
}
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),

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 #include <windows.h>
#include <stdio.h>
#include <iostream>

static const int guide_button_value = 0x0400;

/* the secret function outputs a different struct than the official GetState. */
typedef struct 
{
    unsigned long 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
Last edited on
Topic archived. No new replies allowed.