Skip to content

Commit

Permalink
Fixed Ctrl+C
Browse files Browse the repository at this point in the history
  • Loading branch information
makuke1234 committed Apr 14, 2022
1 parent bca78bf commit e90f9bd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <conio.h>

#define LOCALHOST "127.0.0.1"
#define DEF_PORT 8888
Expand Down Expand Up @@ -46,7 +47,7 @@ static inline void keyboardHandler(udp_t * restrict udp, char * restrict buffer,
while (1)
{
DWORD nEvents;
if (ReadConsoleInputW(hStdIn, records, MAX_RECORD, &nEvents) && (nEvents > 0))
if ((kbhit() || (GetAsyncKeyState(VK_CONTROL) & 0x8000)) && ReadConsoleInputW(hStdIn, records, MAX_RECORD, &nEvents) && (nEvents > 0))
{
// Parse all events to buffer and possibly send out messages
bool breakFlag = false;
Expand All @@ -61,7 +62,7 @@ static inline void keyboardHandler(udp_t * restrict udp, char * restrict buffer,
breakFlag = true;
break;
}
else if (((!kev->bKeyDown) && (kev->wVirtualKeyCode == VK_RETURN)) || (len >= (MAX_BUF - 1)))
else if ((kev->bKeyDown && (kev->wVirtualKeyCode == VK_RETURN)) || (len >= (MAX_BUF - 1)))
{
// Send data
sendBuf[len] = '\0';
Expand Down Expand Up @@ -113,7 +114,6 @@ static inline void keyboardHandler(udp_t * restrict udp, char * restrict buffer,
}
if (breakFlag)
{
printf("Exiting...\n");
break;
}
}
Expand All @@ -124,6 +124,8 @@ static inline void keyboardHandler(udp_t * restrict udp, char * restrict buffer,
}
Sleep(1);
}

printf("Exiting...\n");
udpThread_stopRead(&udpThread);
}

Expand Down Expand Up @@ -336,6 +338,8 @@ void printhelp(const char * restrict app)

int main(int argc, char ** argv)
{
SetConsoleCtrlHandler(NULL, TRUE);

if (!udp_init())
{
fprintf(stderr, "UDP initialization failed!\n");
Expand Down

0 comments on commit e90f9bd

Please sign in to comment.