Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F1 key does not work on modern Windows 11 #49

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions SimpleCom/SerialConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,29 @@ void SimpleCom::SerialConnection::InitSerialPort(const HANDLE hSerial) {
}

/*
* Write key code in KEY_EVENT_RECORD to send buffer.
* If F1 key is found, all of send_data would be flushed and would set true to terminated flag.
* Return true if F1 key is pushed (active close).
* Ask user whether terminate current serial session via dialog box.
* Return true if session should be closed (active close).
*/
bool SimpleCom::SerialConnection::ProcessKeyEvents(const KEY_EVENT_RECORD keyevent, SerialPortWriter& writer, const HANDLE hTermEvent) {
bool SimpleCom::SerialConnection::ShouldTerminate(SerialPortWriter& writer, const HANDLE hTermEvent) {
// Write all keys in the buffer before F1
writer.WriteAsync();

if (keyevent.wVirtualKeyCode == VK_F1) {
// Write all keys in the buffer before F1
writer.WriteAsync();
if (MessageBox(_parent_hwnd, _T("Do you want to leave from this serial session?"), _T("SimpleCom"), MB_YESNO | MB_ICONQUESTION) == IDYES) {
SetEvent(hTermEvent);
return true;
}

if (MessageBox(_parent_hwnd, _T("Do you want to leave from this serial session?"), _T("SimpleCom"), MB_YESNO | MB_ICONQUESTION) == IDYES) {
SetEvent(hTermEvent);
return true;
}
return false;
}

// Return immediately without issueing escape sequence of F1
return false;
/*
* Write key code in KEY_EVENT_RECORD to send buffer.
*/
void SimpleCom::SerialConnection::ProcessKeyEvents(const KEY_EVENT_RECORD keyevent, SerialPortWriter& writer) {

if (keyevent.wVirtualKeyCode == VK_F1) {
// F1 key should not be propagated to peripheral.
return;
}

if (keyevent.bKeyDown && (keyevent.uChar.AsciiChar != '\0')) {
Expand All @@ -104,8 +110,6 @@ bool SimpleCom::SerialConnection::ProcessKeyEvents(const KEY_EVENT_RECORD keyeve
}
}
}

return false;
}

static void StdOutRedirectorLoopInner(const HANDLE hSerial, OVERLAPPED *overlapped, const HANDLE hStdOut, SimpleCom::LogWriter* logwriter) {
Expand Down Expand Up @@ -226,12 +230,15 @@ bool SimpleCom::SerialConnection::StdInRedirector(const HANDLE hSerial, const HA
(inputs[idx + 1].Event.KeyEvent.wRepeatCount == 1 && inputs[idx + 1].Event.KeyEvent.uChar.AsciiChar == 'O') &&
(inputs[idx + 2].Event.KeyEvent.wRepeatCount == 1 && inputs[idx + 2].Event.KeyEvent.uChar.AsciiChar == 'P')) {
idx += 2;
continue;
if (ShouldTerminate(writer, hTermEvent)) {
return true;
}
else{
continue;
}
}

if (ProcessKeyEvents(inputs[idx].Event.KeyEvent, writer, hTermEvent)) {
return true;
}
ProcessKeyEvents(inputs[idx].Event.KeyEvent, writer);
}
else if ((inputs[idx].EventType == WINDOW_BUFFER_SIZE_EVENT) && _useTTYResizer) {
char buf[RINGBUF_SZ];
Expand Down
3 changes: 2 additions & 1 deletion SimpleCom/SerialConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace SimpleCom {
bool _enableStdinLogging;

void InitSerialPort(const HANDLE hSerial);
bool ProcessKeyEvents(const KEY_EVENT_RECORD keyevent, SerialPortWriter& writer, const HANDLE hTermEvent);
bool ShouldTerminate(SerialPortWriter& writer, const HANDLE hTermEvent);
void ProcessKeyEvents(const KEY_EVENT_RECORD keyevent, SerialPortWriter& writer);
bool StdInRedirector(const HANDLE hSerial, const HANDLE hTermEvent);

public:
Expand Down
Loading