How to get a notice when a up aroow key is pressed in C language

Chang Chi 61 Reputation points
2021-02-24T22:29:33.553+00:00

Hi, I like to move a picture on the screen by clicking up, down, right, left arrow on the key board. Is there a way to get a notice in my software when “up arrow key” in keyboard is pressed, as an example. I tried bres=IsInputKey(0); How do I find out what key number is “up-arrow” Is this a right approach, I wonder I use C, and C++ Languages on the platform of Windows10 and Visual studio 2017 Thank you in advance ChangChiTheGraphics

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,757 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,913 questions
{count} votes

Accepted answer
  1. Petrus 【KIM】 546 Reputation points
    2021-02-25T00:19:01.883+00:00

    You need to implement a message map for windows events.

    https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-keydown
    https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)  
    {  
        switch (message)  
        {  
        case WM_KEYDOWN:  
            switch (wParam)  
            {  
            case VK_UP:  
                MessageBoxA(hWnd, "UP", "ARROW", MB_OK);  
                break;  
            }  
            break;  
      
        default:  
            return DefWindowProc(hWnd, message, wParam, lParam);  
        }  
        return 0;  
    }  
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.