Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam777Z committed Jul 22, 2021
1 parent ee845c3 commit c40f88c
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,22 @@ char szClassName[] = "Xbox Guide button map to key";
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
// Try to open the mutex.
HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, 0, "XboxGuideButtonMapToKey1.0");

if (!hMutex)
{
// Mutex doesn't exist. This is the first instance so create the mutex.
hMutex = CreateMutex(0, 0, "XboxGuideButtonMapToKey1.0");
}
else
{
// The mutex exists so this is the second instance so return.
return 0;
}

/* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
hCurrentInstance = hThisInstance;
Expand Down Expand Up @@ -262,7 +273,6 @@ int WINAPI WinMain(HINSTANCE hThisInstance,
else if (d.settings[i].hold_mode == 2)
{
guideDepressed[i] = hrc::now();

}
});

Expand All @@ -281,15 +291,13 @@ int WINAPI WinMain(HINSTANCE hThisInstance,
{
key_tap(d.settings[i].longpress_key, 0, 1);
}

}
else
{
if (d.settings[i].key != 0)
{
key_tap(d.settings[i].key, 0, 1);
}

}
}
});
Expand All @@ -307,8 +315,15 @@ int WINAPI WinMain(HINSTANCE hThisInstance,
TranslateMessage(&messages);
DispatchMessage(&messages);
} // Will get messages until queue is clear

if (messages.message == WM_QUIT)
{
// The app is closing so release the mutex.
ReleaseMutex(hMutex);

break;
}

// Do a tick of any intensive stuff here such as graphics processing
d.update();
Sleep(50);
Expand Down

0 comments on commit c40f88c

Please sign in to comment.