I
I
invzbl32018-03-17 21:32:53
C++ / C#
invzbl3, 2018-03-17 21:32:53

How to implement pressing Ctrl and Shift keys in C/C++ language?

Having read articles on MSDN related to pressing and subsequent output, I would like to see an example of a working code. We need to add them to the program.
I will be grateful.

#include "stdafx.h"
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>

using namespace std;
#define  STR_SIZE 256

int main() {

  setlocale(LC_ALL, "rus");
  HANDLE hIn, hOut;
  DWORD size = STR_SIZE;
  char result[STR_SIZE];

  FreeConsole();
  AllocConsole();
  SetConsoleOutputCP(1251);

  hIn = GetStdHandle(STD_INPUT_HANDLE);
  hOut = GetStdHandle(STD_OUTPUT_HANDLE);

  GetDC(NULL); // дескриптор стола
  POINT p; // структура для координат
  COORD cord; // структура COORD, которая указывает позицию курсора
  cord.X = 0; // координата X структуры COORD
  cord.Y = 0; // координата Y структуры COORD

  while (1) {
    wsprintf(result, "Позиция курсора: ");
    WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
    GetCursorPos(&p);
    wsprintf(result, "x = %4ld, y = %4ld\r\n", p.x, p.y);
    WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cord);
  }
  return 0;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ananiev, 2018-03-18
@SaNNy32

See an example of using SendInput
here: https://batchloaf.wordpress.com/2012/10/18/simulat...

M
MiRPiX, 2018-04-26
@RSM0000

Try this
if(GetAsyncKeyState('button name'))
{
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question