Skip to content

Commit

Permalink
arrow logic was defined
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilLord666 committed Apr 1, 2020
1 parent b29ec2a commit 30ef4a9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ DWORD WINAPI TimerThreadFunc (LPVOID lpParam)

TCHAR outputDir[MAX_PATH];
TCHAR fullOutputName [MAX_PATH];
bool firstSave = true;

while(manager->isRunning())
{
Expand All @@ -76,7 +77,8 @@ DWORD WINAPI TimerThreadFunc (LPVOID lpParam)
if(numberOfWindows == 1)
{
// 1. Send Key Sequence
manager->sendKeysSequence(selectedWindows[0].hWnd, 1, VXD_PORT_DRV);
manager->sendKeysSequence(selectedWindows[0].hWnd, 1, VXD_PORT_DRV, firstSave);
firstSave = false;
// 2. Get last saved file from outputDir
#if WINVER >= 0x0500
_stprintf_s(outputDir, sizeof(outputDir)/sizeof(TCHAR), _T("%hs"), config->getOutputDir().c_str());
Expand Down Expand Up @@ -142,7 +144,8 @@ DWORD WINAPI TimerThreadFunc (LPVOID lpParam)
if(numberOfWindows == 1)
{
// 1. Send Key Sequence
manager->sendKeysSequence(selectedWindows[0].hWnd, 2, VXD_PORT_DRV);
manager->sendKeysSequence(selectedWindows[0].hWnd, 2, VXD_PORT_DRV, firstSave);
firstSave = false;
// 2. Get last saved file from outputDir
#if WINVER >= 0x0500
_stprintf_s(outputDir, sizeof(outputDir)/sizeof(TCHAR), _T("%hs"),
Expand Down Expand Up @@ -217,6 +220,7 @@ DWORD WINAPI TimerThreadFunc (LPVOID lpParam)
// state is Off
else
{
firstSave = true;
channellElapsedTime = 0;
channel2ElapsedTime = 0;
Sleep(CHECK_INTERVAL);
Expand Down Expand Up @@ -298,17 +302,41 @@ void MossbauerLab::Sm2201::SaveManager::AutoSaveManager::activateWindow(HWND win
SendMessage(window, WM_ACTIVATE, WA_CLICKACTIVE, 0);
}

void MossbauerLab::Sm2201::SaveManager::AutoSaveManager::sendKeysSequence(HWND window, int channel, int technology)
bool MossbauerLab::Sm2201::SaveManager::AutoSaveManager::shouldSendArrow(int channel, bool firstSave)
{
// we assume here that initially cursor was set to ch. 1
if (_config->isChannelOneUsing() && _config->isChannelTwoUsing())
{
if (!firstSave)
return true;
if (channel == 1)
return false;
return true; // channel 2
}

if (_config->isChannelOneUsing() && !_config->isChannelTwoUsing())
return false;

if(!_config->isChannelOneUsing() && _config->isChannelTwoUsing())
return firstSave;

return false;
}

void MossbauerLab::Sm2201::SaveManager::AutoSaveManager::sendKeysSequence(HWND window, int channel, int technology, bool firstSave)
{
// 0. make window active
activateWindow(window);

if (technology == WINDOWS_MSG || technology == SEND_INPUT) //sending via Windows MSG
{
std::vector<DWORD> charCodes;
if (channel == 1)
charCodes.push_back(VK_LEFT);
else charCodes.push_back(VK_RIGHT);
if (shouldSendArrow(channel, firstSave))
{
if (channel == 1)
charCodes.push_back(VK_LEFT);
else charCodes.push_back(VK_RIGHT);
}
charCodes.push_back(0x43); // continue
charCodes.push_back(VK_RETURN); // scaling coeff
charCodes.push_back(VK_RETURN); // stop update
Expand All @@ -325,9 +353,12 @@ void MossbauerLab::Sm2201::SaveManager::AutoSaveManager::sendKeysSequence(HWND w
else if (technology == DIRECT_PORT_WRITE)
{
std::vector<BYTE> scanCodes;
if (channel == 1)
scanCodes.push_back(0x4B); // Left Arrow
else scanCodes.push_back(0x4D); // Right Arrow
if (shouldSendArrow(channel, firstSave))
{
if (channel == 1)
scanCodes.push_back(0x4B); // Left Arrow
else scanCodes.push_back(0x4D); // Right Arrow
}
scanCodes.push_back(0x2E); // C
scanCodes.push_back(0x1C); // Enter
scanCodes.push_back(0x1C); // Enter
Expand All @@ -340,9 +371,12 @@ void MossbauerLab::Sm2201::SaveManager::AutoSaveManager::sendKeysSequence(HWND w
else if (technology == VXD_PORT_DRV)
{
std::vector<BYTE> scanCodes;
if (channel == 1)
scanCodes.push_back(0x4B); // Left Arrow
else scanCodes.push_back(0x4D); // Right Arrow
if (shouldSendArrow(channel, firstSave))
{
if (channel == 1)
scanCodes.push_back(0x4B); // Left Arrow
else scanCodes.push_back(0x4D); // Right Arrow
}
scanCodes.push_back(0x2E); // C
scanCodes.push_back(0x1C); // Enter
scanCodes.push_back(0x1C); // Enter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ namespace MossbauerLab
inline bool isRunning() const {return _threadRunning;}
inline MossbauerLab::Sm2201::Config::SchedulerConfig* getConfig() const {return _config;}
void reloadConfig();
void sendKeysSequence(HWND window, int channel, int technology = 0);
void sendKeysSequence(HWND window, int channel, int technology = 0, bool firstSave = false);
private:
void restoreWindow(HWND window);
void activateWindow(HWND window);
bool shouldSendArrow(int channel, bool firstSave);
void sendKeysViaWindowMsg(HWND window, const std::vector<DWORD>& keys, int keyPause = 500);
// HERE we send scancodes from group 1
void sendKeysViaKeyboardController(const std::vector<BYTE>& scanCodes, int keyPause = 500);
Expand Down

0 comments on commit 30ef4a9

Please sign in to comment.