Skip to content

Commit

Permalink
Back to GetAsyncKeyState
Browse files Browse the repository at this point in the history
  • Loading branch information
b1scoito committed Jan 20, 2022
1 parent 19e254f commit 8b48a06
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 168 deletions.
24 changes: 11 additions & 13 deletions clicker/clicker.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pch.hpp"
#include "clicker.hpp"

void c_clicker::init()
void c_clicker::initialize()
{
while ( vars::b_is_running )
{
Expand All @@ -16,14 +16,14 @@ void c_clicker::init()
if ( focus::window_think() && focus::cursor_think() )
{
// left
this->is_left_clicking = ( config.clicker.b_enable_left_clicker && vars::key::is_left_down );
this->is_left_clicking = ( config.clicker.b_enable_left_clicker && vars::key::is_left_down.get());
if ( this->is_left_clicking )
this->send_click(input::mouse_button_t::left, config.clicker.f_left_cps, vars::key::l_is_first_click );
this->send_click(input::mouse_button_t::left, config.clicker.f_left_cps, vars::key::is_left_down.b_state);

// right
this->is_right_clicking = ( config.clicker.b_enable_right_clicker && vars::key::is_right_down);
this->is_right_clicking = ( config.clicker.b_enable_right_clicker && vars::key::is_right_down.get());
if ( this->is_right_clicking )
this->send_click(input::mouse_button_t::right, config.clicker.f_right_cps, vars::key::r_is_first_click );
this->send_click(input::mouse_button_t::right, config.clicker.f_right_cps, vars::key::is_left_down.b_state);
}
}
}
Expand Down Expand Up @@ -79,16 +79,16 @@ void c_clicker::send_click(input::mouse_button_t b_button, float f_cps, bool& b_

++vars::stats::i_clicks_this_session;

log_debug( "[%d]: CPS: [ %.3f ] Delay: [ %.3fms ] Time elapsed: [ %.3fms ] Avg CPS: [ %.3fms ]",
vars::stats::i_clicks_this_session,
f_cps,
( this->delay * 2 ),
elapsed.count(),
log_debug( "[%d]: CPS: [ %.3f ] Delay: [ %.3fms ] Time elapsed: [ %.3fms ] Avg CPS: [ %.3fms ]",
vars::stats::i_clicks_this_session,
f_cps,
( this->delay * 2 ),
elapsed.count(),
vars::stats::f_average_cps
);
}

void c_clicker::update_thread()
void c_clicker::update()
{
while ( vars::b_is_running )
{
Expand All @@ -99,8 +99,6 @@ void c_clicker::update_thread()

if ( this->should_update )
{
log_debug( "Update %.3fms", rate );

// Persistence
if ( config.clicker.b_enable_persistence )
random = rng::random_real<float>( -config.clicker.f_persistence_value,
Expand Down
4 changes: 2 additions & 2 deletions clicker/clicker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class c_clicker
bool is_right_clicking = false;

public:
void init();
void update_thread();
void initialize();
void update();

~c_clicker() = default;
c_clicker() = default;
Expand Down
10 changes: 4 additions & 6 deletions clicker/clicker.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="menu.cpp" />
<ClCompile Include="threads.cpp" />
<ClCompile Include="utils.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -96,7 +95,6 @@
<ClInclude Include="imgui\imstb_truetype.h" />
<ClInclude Include="keybind.hpp" />
<ClInclude Include="pch.hpp" />
<ClInclude Include="threads.hpp" />
<ClInclude Include="utils.hpp" />
<ClInclude Include="vars.hpp" />
<ClInclude Include="menu.hpp" />
Expand All @@ -112,26 +110,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
6 changes: 0 additions & 6 deletions clicker/clicker.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
<ClCompile Include="imgui\imgui_widgets.cpp">
<Filter>utils\imgui</Filter>
</ClCompile>
<ClCompile Include="threads.cpp">
<Filter>utils\threads</Filter>
</ClCompile>
<ClCompile Include="utils.cpp">
<Filter>utils\utils</Filter>
</ClCompile>
Expand Down Expand Up @@ -91,9 +88,6 @@
<ClInclude Include="keybind.hpp">
<Filter>utils\keybind</Filter>
</ClInclude>
<ClInclude Include="threads.hpp">
<Filter>utils\threads</Filter>
</ClInclude>
<ClInclude Include="imgui\imstb_rectpack.h">
<Filter>utils\imgui\stb</Filter>
</ClInclude>
Expand Down
17 changes: 4 additions & 13 deletions clicker/main.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
#include "pch.hpp"

#include "threads.hpp"
#include "clicker.hpp"
#include "menu.hpp"

#include <functional>

INT WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd )
{
std::atexit( [] {
// Dispose stuff
threads::destroy();
vars::b_is_running = false;
} );

std::srand( (unsigned int) std::time( NULL ) );

std::thread(&c_clicker::initialize, c_clicker()).detach();
std::thread(&c_clicker::update, c_clicker()).detach();

// TODO: Custom config folder
config.run( "clicker" );

std::vector<std::function<void()>> functions = {
{ threads::spawn_hooks },
{ threads::spawn_rand },
{ threads::spawn_clicker }
};

for ( auto& func : functions )
std::thread( func ).detach();

log_debug( "Waiting for program end." );
if ( !g_menu->init( 600, 350 ) )
{
Expand Down
4 changes: 2 additions & 2 deletions clicker/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ void c_menu::on_paint( HWND hwnd, int i_width, int i_height )
ImGui::Separator();
ImGui::Text( "Clicks this session: %d", vars::stats::i_clicks_this_session );
ImGui::Text( "Average CPS: %.2f", vars::stats::f_average_cps );
ImGui::Text( "Is left button down: %s", vars::key::is_left_down ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is right button down: %s", vars::key::is_right_down ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is left button down: %s", vars::key::is_left_down.b_state ? ICON_FA_CHECK : ICON_FA_TIMES);
ImGui::Text( "Is right button down: %s", vars::key::is_left_down.b_state ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is hotkey toggled: %s", vars::key::clicker_enabled.get() ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is window focused: %s", focus::window_think() ? ICON_FA_CHECK : ICON_FA_TIMES );
ImGui::Text( "Is cursor visible: %s", focus::is_cursor_visible() ? ICON_FA_CHECK : ICON_FA_TIMES );
Expand Down
101 changes: 0 additions & 101 deletions clicker/threads.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions clicker/threads.hpp

This file was deleted.

11 changes: 9 additions & 2 deletions clicker/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@ namespace input
{
void send_input( mouse_type_t m_type, mouse_side_t m_side )
{
SendMessage( GetForegroundWindow(), (DWORD) m_type, (DWORD) m_side, NULL );
POINT pos; if (!GetCursorPos(&pos)) return;
SendMessage( GetForegroundWindow(), (DWORD) m_type, (DWORD) m_side, MAKELPARAM(pos.x, pos.y) );
}

void click( mouse_input_type_t type, mouse_button_t button )
{
(bool) ( type ) ? (bool) ( button ) ? send_input( mouse_type_t::left_down, mouse_side_t::left ) : send_input( mouse_type_t::right_down, mouse_side_t::right ) : (bool) ( button ) ? send_input( mouse_type_t::left_up, mouse_side_t::left ) : send_input( mouse_type_t::right_up, mouse_side_t::right );
(bool) ( type ) ?
(bool) ( button ) ?
send_input( mouse_type_t::left_down, mouse_side_t::left ):
send_input( mouse_type_t::right_down, mouse_side_t::right ):
(bool) ( button ) ?
send_input( mouse_type_t::left_up, mouse_side_t::left ):
send_input( mouse_type_t::right_up, mouse_side_t::right );
}

}
Expand Down
8 changes: 4 additions & 4 deletions clicker/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace vars
inline auto clicker_enabled = keybind( true, config.clicker.i_key_type, config.clicker.i_clicker_key );
inline auto hide_window = keybind( false, keybind_state_t::toggle, config.clicker.i_hide_window_key );

inline auto is_left_down = false;
inline auto is_right_down = false;
inline auto is_left_down = keybind(false, keybind_state_t::hold, VK_LBUTTON);
inline auto is_right_down = keybind(false, keybind_state_t::hold, VK_RBUTTON);

inline auto l_is_first_click = false;
inline auto r_is_first_click = false;
inline auto l_is_first_click = keybind();
inline auto r_is_first_click = keybind();

inline auto b_inventory_opened = false;
}
Expand Down

0 comments on commit 8b48a06

Please sign in to comment.