Skip to content

Commit

Permalink
Specify the button on the controller to map
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam777Z committed Jul 31, 2021
1 parent e512d78 commit f44a89a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SDL/
SDL/
x64/
10 changes: 9 additions & 1 deletion config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[player1]
; Decimal VKEY code, see the bottom of this file for a list
; Specify the button on the controller to map
; 0: Share button (default)
; 1: Xbox/Guide button
button = 0

; Decimal key code, see the bottom of this file for a list
; Default is 1 (Escape).
; If you set it to zero, set longpress_key correctly, and set hold_mode = 2,
; tapping the guide button for less than longpress_duration will do nothing.
Expand Down Expand Up @@ -31,20 +36,23 @@ delay = 0
; Settings for other players follow

[player2]
button = 0
key = 1
hold_mode = 1
longpress_key = 1
longpress_duration = 1000
delay = 0

[player3]
button = 0
key = 1
hold_mode = 1
longpress_key = 1
longpress_duration = 1000
delay = 0

[player4]
button = 0
key = 1
hold_mode = 1
longpress_key = 1
Expand Down
28 changes: 17 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,14 @@ void key_tap(int8_t code, int64_t delay, int64_t duration)

struct PlayerSettings
{
int64_t button;
int64_t key;
int64_t hold_mode;
int64_t longpress_key;
int64_t longpress_duration;
int64_t delay;
};

bool inline is_button_pressed(int i)
{
return SDL_GameControllerGetButton(controllers[i], SDL_CONTROLLER_BUTTON_MISC1) == SDL_PRESSED;
}

void print(int8_t v)
{
printf("%i", (int)v);
Expand Down Expand Up @@ -243,6 +239,12 @@ struct GlobalData
return dat;
}

bool inline is_button_pressed(int i)
{
GlobalData& d = GlobalData::get();
return SDL_GameControllerGetButton(controllers[i], (d.settings[i].button == 1 ? SDL_CONTROLLER_BUTTON_GUIDE : SDL_CONTROLLER_BUTTON_MISC1)) == SDL_PRESSED;
}

void update()
{
SDL_JoystickUpdate();
Expand Down Expand Up @@ -280,24 +282,28 @@ struct GlobalData
error("Couldn't load config.ini. Using defaults.");
}

settings[0].button = ini.getInteger("player1", "button", 0);
settings[0].key = ini.getInteger("player1", "key", 1);
settings[0].hold_mode = ini.getInteger("player1", "hold_mode", 1);
settings[0].longpress_key = ini.getInteger("player1", "longpress_key", 1);
settings[0].longpress_duration = ini.getInteger("player1", "longpress_duration", 1000);
settings[0].delay = ini.getInteger("player1", "delay", 0);

settings[1].button = ini.getInteger("player2", "button", 0);
settings[1].key = ini.getInteger("player2", "key", 1);
settings[1].hold_mode = ini.getInteger("player2", "hold_mode", 1);
settings[1].longpress_key = ini.getInteger("player2", "longpress_key", 1);
settings[1].longpress_duration = ini.getInteger("player2", "longpress_duration", 1000);
settings[1].delay = ini.getInteger("player2", "delay", 0);

settings[2].button = ini.getInteger("player3", "button", 0);
settings[2].key = ini.getInteger("player3", "key", 1);
settings[2].hold_mode = ini.getInteger("player3", "hold_mode", 1);
settings[2].longpress_key = ini.getInteger("player3", "longpress_key", 1);
settings[2].longpress_duration = ini.getInteger("player3", "longpress_duration", 1000);
settings[2].delay = ini.getInteger("player3", "delay", 0);

settings[3].button = ini.getInteger("player4", "button", 0);
settings[3].key = ini.getInteger("player4", "key", 1);
settings[3].hold_mode = ini.getInteger("player4", "hold_mode", 1);
settings[3].longpress_key = ini.getInteger("player4", "longpress_key", 1);
Expand Down Expand Up @@ -340,15 +346,15 @@ int WINAPI WinMain(_In_ HINSTANCE hThisInstance, _In_opt_ HINSTANCE hPrevInstanc
return 0;
}

/* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
// This is the handle for our window
MSG messages; // Here messages to the application are saved
hCurrentInstance = hThisInstance;

WNDCLASS wincl;
ZeroMemory(&wincl, sizeof(wincl));
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProc; /* This function is called by windows */
wincl.lpfnWndProc = WindowProc; // This function is called by windows
ATOM szClassName = RegisterClass(&wincl);
hWnd = CreateWindow((LPCTSTR)szClassName, "", 0, 0, 0, 0, 0, NULL, NULL, hThisInstance, NULL);

Expand Down Expand Up @@ -405,7 +411,7 @@ int WINAPI WinMain(_In_ HINSTANCE hThisInstance, _In_opt_ HINSTANCE hPrevInstanc

SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");

/* Initialize SDL */
// Initialize SDL
if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0) {
fatal_error(strcat("Couldn't initialize SDL: %s", SDL_GetError()));
}
Expand Down Expand Up @@ -450,7 +456,7 @@ int WINAPI WinMain(_In_ HINSTANCE hThisInstance, _In_opt_ HINSTANCE hPrevInstanc

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
/* Handle the messages */
// Handle the messages
switch (uMsg)
{
case WM_CREATE:
Expand All @@ -461,7 +467,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
notifyIconData.hWnd = hwnd;
notifyIconData.uID = ID_TRAY_APP_ICON;
notifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
notifyIconData.uCallbackMessage = WM_SYSICON; //Set up our invented Windows Message
notifyIconData.uCallbackMessage = WM_SYSICON; // Set up our invented Windows Message
notifyIconData.hIcon = (HICON)LoadImage(hCurrentInstance, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
strncpy(notifyIconData.szTip, szTIP, sizeof(szTIP));
Shell_NotifyIcon(NIM_ADD, &notifyIconData);
Expand Down
Binary file modified resource.rc
Binary file not shown.

0 comments on commit f44a89a

Please sign in to comment.