Skip to content

Commit c981275

Browse files
author
Sebi
committed
Adding first (windows only) version of external direct input (stolen from the old code)
1 parent 2576f4d commit c981275

File tree

7 files changed

+82
-11
lines changed

7 files changed

+82
-11
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ ADD_Executable(DasherUI
7272
${PROJECT_SOURCE_DIR}/src/DasherUIScreen.h
7373
${PROJECT_SOURCE_DIR}/src/SocketInput.cpp
7474
${PROJECT_SOURCE_DIR}/src/SocketInput.h
75+
${PROJECT_SOURCE_DIR}/src/OSOutput.cpp
76+
${PROJECT_SOURCE_DIR}/src/OSOutput.h
7577
${PROJECT_SOURCE_DIR}/src/main.cpp
7678
)
7779
target_include_directories(DasherUI PUBLIC ${CMAKE_CURRENT_LIST_DIR}/Thirdparty/)

src/DasherController.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ DasherController::DasherController(Dasher::CSettingsStore* pSettingsStore): CDas
66
{
77
ScreenModule = std::make_shared<DasherUIScreen>();
88
CDashIntfScreenMsgs::ChangeScreen(ScreenModule.get());
9+
10+
OSOutputModule = std::make_unique<OSOutput>();
911
}
1012

1113
void DasherController::editOutput(const std::string& strText, Dasher::CDasherNode* pNode) {
@@ -15,13 +17,15 @@ void DasherController::editOutput(const std::string& strText, Dasher::CDasherNod
1517
}
1618
Buffer.append(strText);
1719
Cursor += static_cast<unsigned int>(strText.length());
20+
OSOutputModule->outputCharacter(strText);
1821
CDasherInterfaceBase::editOutput(strText, pNode);
1922
}
2023

2124
void DasherController::editDelete(const std::string& strText, Dasher::CDasherNode* pNode) {
2225
if(0 == Buffer.compare(Buffer.length() - strText.length(), strText.length(), strText))
2326
{
2427
Buffer.erase(Buffer.length() - strText.length(), strText.length());
28+
OSOutputModule->deleteCharacter();
2529
}
2630
CDasherInterfaceBase::editDelete(strText, pNode);
2731
}
@@ -43,7 +47,6 @@ unsigned DasherController::ctrlDelete(bool bForwards, Dasher::CControlManager::E
4347
}
4448
if(!bForwards) Cursor--;
4549
return Cursor;
46-
4750
}
4851

4952
std::string DasherController::GetContext(unsigned iStart, unsigned iLength)

src/DasherController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "imgui_internal.h"
77
#include <memory>
88

9+
#include "OSOutput.h"
910
#include "SocketInput.h"
1011

1112

@@ -47,4 +48,5 @@ class DasherController : public Dasher::CDashIntfScreenMsgs
4748
//Modules
4849
std::shared_ptr<DasherUIScreen> ScreenModule;
4950
std::shared_ptr<SocketInput> SocketInputModule;
51+
std::shared_ptr<OSOutput> OSOutputModule;
5052
};

src/OSOutput.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "OSOutput.h"
2+
3+
#include <codecvt>
4+
#include <string>
5+
6+
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
7+
#include <windows.h>
8+
#include <stringapiset.h>
9+
#include <WinUser.h>
10+
#undef WIN32_LEAN_AND_MEAN
11+
12+
OSOutput::OSOutput(){}
13+
14+
OSOutput::~OSOutput(){}
15+
16+
void OSOutput::deleteCharacter()
17+
{
18+
INPUT fakekey[2];
19+
fakekey[0].type = fakekey[1].type = INPUT_KEYBOARD;
20+
fakekey[0].ki.wVk = fakekey[1].ki.wVk = VK_BACK;
21+
fakekey[0].ki.time = fakekey[1].ki.time = 0;
22+
fakekey[1].ki.dwFlags = KEYEVENTF_KEYUP;
23+
24+
SendInput(2, fakekey, sizeof(INPUT));
25+
}
26+
27+
void OSOutput::outputCharacter(const std::string &sText)
28+
{
29+
INPUT fakekey[2];
30+
if(sText[0] == '\r' && sText[1] == '\n') {
31+
// Newline, so we want to fake an enter
32+
fakekey[0].type = fakekey[1].type = INPUT_KEYBOARD;
33+
fakekey[0].ki.wVk = fakekey[1].ki.wVk = VK_RETURN;
34+
fakekey[0].ki.time = fakekey[1].ki.time = 0;
35+
fakekey[1].ki.dwFlags = KEYEVENTF_KEYUP;
36+
SendInput(2, fakekey, sizeof(INPUT));
37+
}
38+
else {
39+
int wchars_num = MultiByteToWideChar( CP_UTF8 , 0 , sText.c_str() , -1, nullptr , 0 );
40+
wchar_t* wstr = new wchar_t[wchars_num];
41+
MultiByteToWideChar( CP_UTF8 , 0 , sText.c_str() , -1, wstr , wchars_num );
42+
43+
for(int i = 0; i < wchars_num; ++i) {
44+
fakekey[0].type = INPUT_KEYBOARD;
45+
fakekey[0].ki.dwFlags = KEYEVENTF_UNICODE;
46+
fakekey[0].ki.wVk = 0;
47+
fakekey[0].ki.time = NULL;
48+
fakekey[0].ki.wScan = wstr[i];
49+
SendInput(1, fakekey, sizeof(INPUT));
50+
}
51+
52+
delete[] wstr;
53+
}
54+
}

src/OSOutput.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
#include <xstring>
3+
4+
5+
class OSOutput
6+
{
7+
public:
8+
OSOutput();
9+
virtual ~OSOutput();
10+
11+
void deleteCharacter();
12+
void outputCharacter(const std::string& sText);
13+
};

src/SocketInput.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include "DasherInterfaceBase.h"
77
#include "DasherModel.h"
88

9-
SocketInput::SocketInput(CSettingsUser* Creator, Dasher::CDashIntfSettings* Controller, Dasher::CFrameRate* pFramerate): CScreenCoordInput(0, _("Socket Input")),
9+
SocketInput::SocketInput(CSettingsUser* Creator, Dasher::CDasherInterfaceBase* Controller, Dasher::CFrameRate* pFramerate): CScreenCoordInput(0, _("Socket Input")),
1010
CDefaultFilter(Creator, Controller, pFramerate, 2, "Socket Mode")
1111
{
12-
xLabel = Controller->GetStringParameter(Dasher::Parameter::SP_SOCKET_INPUT_X_LABEL);
13-
yLabel = Controller->GetStringParameter(Dasher::Parameter::SP_SOCKET_INPUT_Y_LABEL);
12+
xLabel = GetStringParameter(Dasher::Parameter::SP_SOCKET_INPUT_X_LABEL);
13+
yLabel = GetStringParameter(Dasher::Parameter::SP_SOCKET_INPUT_Y_LABEL);
1414
}
1515

1616
SocketInput::~SocketInput()
@@ -22,7 +22,7 @@ bool SocketInput::GetScreenCoords(Dasher::screenint& iX, Dasher::screenint& iY,
2222
{
2323
const Dasher::CDasherView::ScreenRegion screenRegion = pView->VisibleRegion();
2424

25-
const double vectorLength = std::min(Dasher::CDasherModel::ORIGIN_Y - screenRegion.minY, screenRegion.maxY - Dasher::CDasherModel::ORIGIN_Y);
25+
const double vectorLength = static_cast<double>(std::min(Dasher::CDasherModel::ORIGIN_Y - screenRegion.minY, screenRegion.maxY - Dasher::CDasherModel::ORIGIN_Y));
2626
const double normalization = sqrt(lastRelativeX * lastRelativeX + lastRelativeY * lastRelativeY);
2727

2828
pView->Dasher2Screen(
@@ -35,7 +35,7 @@ bool SocketInput::GetScreenCoords(Dasher::screenint& iX, Dasher::screenint& iY,
3535

3636
void SocketInput::startListen()
3737
{
38-
session_acceptor = std::make_unique<asio::ip::tcp::acceptor>(io_service, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), static_cast<short>(Controller->GetLongParameter(Dasher::LP_SOCKET_PORT))));
38+
session_acceptor = std::make_unique<asio::ip::tcp::acceptor>(io_service, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), static_cast<short>(GetLongParameter(Dasher::LP_SOCKET_PORT))));
3939

4040
receiveThread = std::thread([this](){
4141

@@ -80,7 +80,7 @@ void SocketInput::startListen()
8080
stop();
8181
}
8282
}
83-
} catch (std::exception& e)
83+
} catch (std::exception&)
8484
{
8585
std::cout << "Wrong format for socket input" << std::endl;
8686
}

src/SocketInput.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class SocketInput : public Dasher::CScreenCoordInput, public Dasher::CDefaultFilter
99
{
1010
public:
11-
SocketInput(CSettingsUser* Creator, Dasher::CDashIntfSettings* Controller, Dasher::CFrameRate* pFramerate);
11+
SocketInput(CSettingsUser* Creator, Dasher::CDasherInterfaceBase* Controller, Dasher::CFrameRate* pFramerate);
1212
virtual ~SocketInput();
1313

1414
bool GetScreenCoords(Dasher::screenint& iX, Dasher::screenint& iY, Dasher::CDasherView* pView) override;
@@ -23,9 +23,6 @@ class SocketInput : public Dasher::CScreenCoordInput, public Dasher::CDefaultFil
2323
Dasher::screenint lastX = 0;
2424
Dasher::screenint lastY = 0;
2525

26-
//Dasher Stuff
27-
Dasher::CDashIntfSettings* Controller;
28-
2926
//Commands
3027
std::string xLabel;
3128
std::string yLabel;

0 commit comments

Comments
 (0)