Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Input to target window more accurately prepared now
Browse files Browse the repository at this point in the history
  • Loading branch information
rozmansi committed Feb 9, 2016
1 parent 12a7978 commit 6c65f6a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 60 deletions.
109 changes: 49 additions & 60 deletions ZRCola/zrcolafrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,73 +99,17 @@ void wxZRColaFrame::OnSend(wxCommandEvent& event)

void wxZRColaFrame::OnSendComposed(wxCommandEvent& event)
{
if (m_hWndSource) {
// Get text and its length (in Unicode characters). Prepare the INPUT table.
wxString text = m_panel->m_composed->GetValue();
std::vector<INPUT>::size_type n = text.length();
if (n) {
wxString::const_iterator i_text = text.begin();
std::vector<INPUT> input(n);
for (std::vector<INPUT>::size_type i = 0; i < n; i++, i_text++) {
INPUT &inp = input[i];
inp.type = INPUT_KEYBOARD;
inp.ki.wVk = 0;
inp.ki.wScan = *i_text;
inp.ki.dwFlags = KEYEVENTF_UNICODE;
inp.ki.time = 0;
inp.ki.dwExtraInfo = 0;
}

// Return focus to the source window and send the input.
::SetActiveWindow(m_hWndSource);
::SetForegroundWindow(m_hWndSource);
::Sleep(200);
::SendInput(n, input.data(), sizeof(INPUT));
m_hWndSource = NULL;
m_hotkey = -1;

// Select all input in composer and decomposed to prepare for the overwrite next time.
m_panel->m_decomposed->SelectAll();
m_panel->m_composed->SelectAll();
}
}
if (m_hWndSource)
DoSend(m_panel->m_composed->GetValue());

event.Skip();
}


void wxZRColaFrame::OnSendDecomposed(wxCommandEvent& event)
{
if (m_hWndSource) {
// Get text and its length (in Unicode characters). Prepare the INPUT table.
wxString text = m_panel->m_decomposed->GetValue();
std::vector<INPUT>::size_type n = text.length();
if (n) {
wxString::const_iterator i_text = text.begin();
std::vector<INPUT> input(n);
for (std::vector<INPUT>::size_type i = 0; i < n; i++, i_text++) {
INPUT &inp = input[i];
inp.type = INPUT_KEYBOARD;
inp.ki.wVk = 0;
inp.ki.wScan = *i_text;
inp.ki.dwFlags = KEYEVENTF_UNICODE;
inp.ki.time = 0;
inp.ki.dwExtraInfo = 0;
}

// Return focus to the source window and send the input.
::SetActiveWindow(m_hWndSource);
::SetForegroundWindow(m_hWndSource);
::Sleep(200);
::SendInput(n, input.data(), sizeof(INPUT));
m_hWndSource = NULL;
m_hotkey = -1;

// Select all input in composer and decomposed to prepare for the overwrite next time.
m_panel->m_decomposed->SelectAll();
m_panel->m_composed->SelectAll();
}
}
if (m_hWndSource)
DoSend(m_panel->m_decomposed->GetValue());

event.Skip();
}
Expand Down Expand Up @@ -225,6 +169,51 @@ void wxZRColaFrame::OnAbout(wxCommandEvent& event)
}


void wxZRColaFrame::DoSend(const wxString& str)
{
// Prepare the INPUT table.
wxString::size_type n = str.length();
wxString::const_iterator i_str = str.begin();
std::vector<INPUT> input(n);
for (std::vector<INPUT>::size_type i = 0; i < n; i++, i_str++) {
wxString::char_type c = *i_str;
INPUT &inp = input[i];
inp.type = INPUT_KEYBOARD;
inp.ki.dwFlags = KEYEVENTF_UNICODE;
inp.ki.time = 0;
inp.ki.dwExtraInfo = 0;
if (c == L'\n') {
// Enter (Return) key is sent as CR virtual key code.
inp.ki.wVk = VK_RETURN;
inp.ki.wScan = L'\r';
} else if (L'a' <= c && c <= L'z') {
// Small letters have the same virtual key code as their uppercase counterparts.
inp.ki.wVk = (WORD)c + L'A' - L'a';
inp.ki.wScan = c;
} else if (L'A' <= c && c <= L'Z' || L'0' <= c && c <= L'0' || c == L' ') {
// Letters and symbols with matching virtual key codes.
inp.ki.wVk = c;
inp.ki.wScan = c;
} else {
inp.ki.wVk = 0;
inp.ki.wScan = c;
}
}

// Return focus to the source window and send the input.
::SetActiveWindow(m_hWndSource);
::SetForegroundWindow(m_hWndSource);
::Sleep(200);
::SendInput(input.size(), input.data(), sizeof(INPUT));
m_hWndSource = NULL;
m_hotkey = -1;

// Select all input in composer and decomposed to prepare for the overwrite next time.
m_panel->m_decomposed->SelectAll();
m_panel->m_composed->SelectAll();
}


WXLRESULT wxZRColaFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
if (message == WM_HOTKEY) {
Expand Down
3 changes: 3 additions & 0 deletions ZRCola/zrcolafrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class wxZRColaFrame : public wxZRColaFrameBase
void OnAbout(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();

private:
void DoSend(const wxString& str);

protected:
virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);

Expand Down

0 comments on commit 6c65f6a

Please sign in to comment.