跳到正文

剪贴板

剪贴板 boj80y3t

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
#include<windows.h>
#define N 50
#define M 1000000
#define inf 0x3f3f3f3f
#define ll long long

using namespace std;

const int PRESSED = 1;
const int PRESS = 2;
const int RELEASE = 4;

struct KeyListener
{
	int nVirtKey;
	short lastState;
	KeyListener(int nVirtKey)
	{
		this->nVirtKey = nVirtKey;
    	lastState = GetKeyState(nVirtKey);
	}
	int getState()
	{
		int re = 0;
			short state = GetKeyState(nVirtKey);
		if (state & 128)
			re |= PRESSED;
		if (((lastState ^ state) & 1)||(lastState == 0 && state == -128))
			re |= PRESS;
		if (((lastState ^ state)^((lastState^state)>>7))&1)
			re |= RELEASE;
		lastState = state;
		return re;
	}
};

void setTextColor(int code)
{
	printf("\033[38;5;%dm", code);
}

void setTextColor(int r, int g, int b)//[0,5]
{
	setTextColor(16 + r * 36 + g * 6 + b);
}

void setTextNeutralColor(int l)//[0,23]
{
	setTextColor(232 + l);
}

void setBackgroundColor(int code)
{
	printf("\033[48;5;%dm", code);
}

void setBackgroundColor(int r, int g, int b)//[0,5]
{
	setBackgroundColor(16 + r * 36 + g * 6 + b);
}

void setBackgroundNeutralColor(int l)//[0,23]
{
	setBackgroundColor(232 + l);
}

void cancelColorSet()
{
	printf("\033[m");
}

HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
HWND hWnd = GetConsoleWindow();

void disableQuickEditMode()
{
	DWORD mode;
	GetConsoleMode(hIn, &mode);
	mode &= ~ENABLE_QUICK_EDIT_MODE;
	SetConsoleMode(hIn, mode);
}
void hideCursor()
{
	CONSOLE_CURSOR_INFO cursorInfo;
	GetConsoleCursorInfo(hOut, &cursorInfo);
	cursorInfo.bVisible = false;
	SetConsoleCursorInfo(hOut, &cursorInfo);
}
void showCursor()
{
	CONSOLE_CURSOR_INFO cursorInfo;
	GetConsoleCursorInfo(hOut, &cursorInfo);
	cursorInfo.bVisible = true;
	SetConsoleCursorInfo(hOut, &cursorInfo);
}
void setCursorSize(DWORD size)
{
	CONSOLE_CURSOR_INFO cursorInfo;
	GetConsoleCursorInfo(hOut, &cursorInfo);
	cursorInfo.dwSize = size;
	SetConsoleCursorInfo(hOut, &cursorInfo);
}
void floatConsole()
{
	SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_DRAWFRAME);
}
void unfloatConsole()
{
	SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_DRAWFRAME);
}
void killConsoleCloseButton()
{
	DeleteMenu(GetSystemMenu(hWnd, FALSE), SC_CLOSE, MF_DISABLED);
	DrawMenuBar(hWnd);
}
void setCursorPos(short x, short y)
{
	SetConsoleCursorPosition(hOut, { x,y });
}
void lockWindowSize()
{
	RECT rc;
	GetWindowRect(hWnd, &rc);
	SetWindowLongPtr(hWnd,
		GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX);
	SetWindowPos(hWnd,
		NULL,
		rc.left,
		rc.top,
		rc.right - rc.left, rc.bottom - rc.top,
		NULL);
}
void setConsoleSize(int x, int y, int col, int row)
{
	CONSOLE_FONT_INFO consoleCurrentFont;
	COORD bufferSize, fontSize;
	GetCurrentConsoleFont(hOut, false, &consoleCurrentFont);
	fontSize = GetConsoleFontSize(hOut, consoleCurrentFont.nFont);
	bufferSize.X = col;
	bufferSize.Y = row;
	SetConsoleScreenBufferSize(hOut, bufferSize);
	MoveWindow(hWnd, x, y, (col + 4) * fontSize.X, (row + 2) * fontSize.Y + (fontSize.Y >> 1) - 1, true);
}
POINT getCursorPos()
{
	POINT p;
	GetCursorPos(&p);
	ScreenToClient(hWnd, &p);
	return p;
}
void moveCursor(int x, int y)
{
	SetConsoleCursorPosition(hOut, { (short)x,(short)y });
}

int rand(int from, int to)
{
	int x = to + 1;
	while (x > to)
		x = from + std::rand() / ((RAND_MAX + 1u) / (to - from + 1));
	return x;
}