Code Monkey home page Code Monkey logo

hotkey-blocker's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @ZombieRoxtar!
  • ๐Ÿ‘€ Iโ€™m interested in game modding, mostly.

hotkey-blocker's People

Contributors

aroxby avatar zombieroxtar avatar

Watchers

 avatar  avatar

hotkey-blocker's Issues

Window Message Loop

Please look up how to create a message only window and make use of WndProc

Consider:

#include <iostream>
#include <windows.h>
using namespace std;

//This is our message callback
LRESULT CALLBACK  WndProc(HWND, UINT, WPARAM, LPARAM);

int main()
{
    //Create window class
    WNDCLASS wc;
    memset(&wc, 0, sizeof(wc));
    wc.cbSize = sizeof(wc);
    wc.lpfnWndProc  = WndProc;
    wc.lpszClassName  = "myWindowClass";
    RegisterClass(&wc);

    //Create window (uses HWND_MESSAGE as the parent window to create message only window)
    HWND window = CreateWindow(szWndClass, "HotkeyMesageWindow", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
    if(!window)
    {
        cerr << "Can't create window!" << endl;
        exit(1);
    }

    // Main message loop:
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return (int) msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

DON'T use this code exactly, It will need adjusted to use peek message. Right now it's waiting for the user to click the 'x' which you won't have on your message only window. I'll get back to you later with better code.

It bwoke!

Dude, I never moved that code to the message loop before because then it doesn't hear anything!

Array Type

I declared a managed array of keys to make future changes to the keys faster. Subsequently, I had to calculate and store the array length. What's the best choice here?
This issue is summarized in the comment on line 21.

App Lag

If you run this program and focus Notepad2 and then press F1, then Notepad2 will lock up until you focus the console window again.

Exit Hotkey

You have to press the exit hotkey twice to close the program. Also, this input is never passed to the foreground window! I guess I don't really need a hotkey to close the program...
This issue is summarized in the comment on line 22.

Hotkey Message

Surely you must read this and cringe a little.

            int daKey = 0;
            switch (msg.wParam)
            {
            case 0:
                keepGoing = false;
                break;
            case 1:
                daKey = 1;
                break;
            case 2:
                daKey = 2;
                break;
            case 3:
                daKey = 3;
                break;
            case 4:
                daKey = 4;
            }

why not

int daKey = msg.wParam;
if(daKey==0) keepGoing = false;

?

Window Message Lop

Your main loop should probably look like this:

do
{
    if(PeekMessage(...))
    {
        TranslateMessage(&msg);
        //This will call your WndProc
        DispatchMessage(&msg);
    }
    Sleep(0);
} while(keepGoing);

PostMessage vs. Send Message

I really couldn't care about PostMessage vs Send Message, but I want to be sure both messages are received and in that order.
This issue is summarized in the comment block on lines 64-67.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.