commit 44010caed009d1ae8e2734a90ceba4f7fb5b1481
parent 4927fea93fc99cb3eba1bca3a5cd931a8e0a83a7
Author: Konjahin Anton <koniahin.ant@yandex.ru>
Date: Sun, 18 Jun 2017 11:20:54 +0300
Added gitignore, fixed formatting
Diffstat:
A | .gitignore | | | 4 | ++++ |
M | keyboard.c | | | 45 | ++++++++++++++++++++++----------------------- |
M | keyboard.h | | | 11 | +++++------ |
M | main.c | | | 151 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
4 files changed, 108 insertions(+), 103 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,3 @@
+*.exe
+*.obj
+*~
+\ No newline at end of file
diff --git a/keyboard.c b/keyboard.c
@@ -6,37 +6,37 @@
#include "keyboard.h"
void setUpInput(INPUT *ip) {
- ip->type = INPUT_KEYBOARD;
- ip->ki.wScan = 0;
- ip->ki.time = 0;
- ip->ki.dwExtraInfo = 0;
+ ip->type = INPUT_KEYBOARD;
+ ip->ki.wScan = 0;
+ ip->ki.time = 0;
+ ip->ki.dwExtraInfo = 0;
}
void hold(INPUT *ip, WORD keyCode) {
- setUpInput(ip);
- ip->ki.wVk = keyCode;
- ip->ki.dwFlags = 0;
- SendInput(1, ip, sizeof(INPUT));
+ setUpInput(ip);
+ ip->ki.wVk = keyCode;
+ ip->ki.dwFlags = 0;
+ SendInput(1, ip, sizeof(INPUT));
}
void release(INPUT *ip, WORD keyCode) {
- setUpInput(ip);
- ip->ki.wVk = keyCode;
- ip->ki.dwFlags = KEYEVENTF_KEYUP;
- SendInput(1, ip, sizeof(INPUT));
+ setUpInput(ip);
+ ip->ki.wVk = keyCode;
+ ip->ki.dwFlags = KEYEVENTF_KEYUP;
+ SendInput(1, ip, sizeof(INPUT));
}
void press(INPUT *ip, WORD keyCode) {
- hold(ip, keyCode);
- release(ip, keyCode);
+ hold(ip, keyCode);
+ release(ip, keyCode);
}
void getCharForKey(WORD keyCode, wchar_t* buffer, size_t bufferLength) {
- HKL keyboardLayout = GetKeyboardLayout(0);
- UINT scanCode = MapVirtualKeyEx(keyCode, MAPVK_VK_TO_VSC, keyboardLayout);
-
- BYTE keyState[256] = {0};
- GetKeyboardState(keyState);
-
- ToUnicodeEx(keyCode, scanCode, keyState, buffer, bufferLength, 0, keyboardLayout);
-}
-\ No newline at end of file
+ HKL keyboardLayout = GetKeyboardLayout(0);
+ UINT scanCode = MapVirtualKeyEx(keyCode, MAPVK_VK_TO_VSC, keyboardLayout);
+
+ BYTE keyState[256] = {0};
+ GetKeyboardState(keyState);
+
+ ToUnicodeEx(keyCode, scanCode, keyState, buffer, bufferLength, 0, keyboardLayout);
+}
diff --git a/keyboard.h b/keyboard.h
@@ -11,7 +11,7 @@
* Arguments:
* ip - INPUT structure from winuser.h
* keyCode - WORD with virtual key-code from https://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx
-*/
+ */
void hold(INPUT *ip, WORD keyCode);
/**
@@ -19,7 +19,7 @@ void hold(INPUT *ip, WORD keyCode);
* Arguments:
* ip - INPUT structure from winuser.h
* keyCode - WORD with virtual key-code from https://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx
-*/
+ */
void release(INPUT *ip, WORD keyCode);
/**
@@ -27,7 +27,7 @@ void release(INPUT *ip, WORD keyCode);
* Arguments:
* ip - INPUT structure from winuser.h
* keyCode - WORD with virtual key-code from https://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx
-*/
+ */
void press(INPUT *ip, WORD keyCode);
/**
@@ -37,5 +37,5 @@ void press(INPUT *ip, WORD keyCode);
* keyCode - WORD with virtual key-code from https://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx
* buffer - wxhar_t* wide chars buffer for output
* bufferLength size_t size of buffer
-*/
-void getCharForKey(WORD keyCode, wchar_t* buffer, size_t bufferLength);
-\ No newline at end of file
+ */
+void getCharForKey(WORD keyCode, wchar_t* buffer, size_t bufferLength);
diff --git a/main.c b/main.c
@@ -13,81 +13,85 @@
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
- switch(msg) {
- case WM_CREATE:
- HWND hwndButton = CreateWindow("BUTTON", "<", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
- 10, 10, 40, 40, hwnd, (HMENU) BUTTON_LEFT, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
- hwndButton = CreateWindow("BUTTON", "Esc", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
- 60, 10, 40, 40, hwnd, (HMENU) BUTTON_ESCAPE, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
- hwndButton = CreateWindow("BUTTON", ">", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
- 110, 10, 40, 40, hwnd, (HMENU) BUTTON_RIGHT, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
- break;
-
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
-
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- case WM_COMMAND:
- // processed only button's clicks
- if (HIWORD(wParam) != BN_CLICKED) {
- break;
- }
-
- INPUT input;
- switch(LOWORD(wParam)) {
- case BUTTON_LEFT:
- press(&input, VK_LEFT);
- break;
- case BUTTON_RIGHT:
- press(&input, VK_RIGHT);
- break;
- case BUTTON_ESCAPE:
- press(&input, VK_ESCAPE);
- break;
- }
- break;
-
- // move window by user drag
- case WM_NCHITTEST:
- LRESULT hit = DefWindowProc(hwnd, msg, wParam, lParam);
- if (hit == HTCLIENT) hit = HTCAPTION;
- return hit;
-
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
+ switch(msg) {
+ case WM_CREATE:
+ HWND hwndButton = CreateWindow("BUTTON", "<", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
+ 10, 10, 40, 40, hwnd, (HMENU) BUTTON_LEFT,
+ (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
+ hwndButton = CreateWindow("BUTTON", "Esc", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
+ 60, 10, 40, 40, hwnd, (HMENU) BUTTON_ESCAPE,
+ (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
+ hwndButton = CreateWindow("BUTTON", ">", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
+ 110, 10, 40, 40, hwnd, (HMENU) BUTTON_RIGHT,
+ (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
+ break;
+
+ case WM_CLOSE:
+ DestroyWindow(hwnd);
+ break;
+
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+
+ case WM_COMMAND:
+ // processed only button's clicks
+ if (HIWORD(wParam) != BN_CLICKED) {
+ break;
+ }
+
+ INPUT input;
+ switch(LOWORD(wParam)) {
+ case BUTTON_LEFT:
+ press(&input, VK_LEFT);
+ break;
+ case BUTTON_RIGHT:
+ press(&input, VK_RIGHT);
+ break;
+ case BUTTON_ESCAPE:
+ press(&input, VK_ESCAPE);
+ break;
}
- return 0;
+ break;
+
+ // move window by user drag
+ case WM_NCHITTEST:
+ LRESULT hit = DefWindowProc(hwnd, msg, wParam, lParam);
+ if (hit == HTCLIENT) hit = HTCAPTION;
+ return hit;
+
+ default:
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+ }
+
+ return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
- const char className[] = "keyTuneWindowClass";
- WNDCLASSEX wc = {0};
-
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.lpfnWndProc = WndProc;
- wc.hInstance = hInstance;
- wc.hbrBackground = 0;
- wc.lpszClassName = className;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
-
- RegisterClassEx(&wc);
-
- HWND hwnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE, className,
- "Keytune", WS_POPUP | WS_VISIBLE | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 160,
- 60, NULL, NULL, hInstance, NULL);
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
-
- MSG Msg;
- while(GetMessage(&Msg, NULL, 0, 0) > 0) {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
-
- return Msg.wParam;
-}
-\ No newline at end of file
+ const char className[] = "keyTuneWindowClass";
+ WNDCLASSEX wc = {0};
+
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.lpfnWndProc = WndProc;
+ wc.hInstance = hInstance;
+ wc.hbrBackground = 0;
+ wc.lpszClassName = className;
+ wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
+
+ RegisterClassEx(&wc);
+
+ HWND hwnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE, className,
+ "Keytune", WS_POPUP | WS_VISIBLE | WS_SYSMENU, CW_USEDEFAULT,
+ CW_USEDEFAULT, 160, 60, NULL, NULL, hInstance, NULL);
+ ShowWindow(hwnd, nCmdShow);
+ UpdateWindow(hwnd);
+
+ MSG Msg;
+ while(GetMessage(&Msg, NULL, 0, 0) > 0) {
+ TranslateMessage(&Msg);
+ DispatchMessage(&Msg);
+ }
+
+ return Msg.wParam;
+}