Skip to content

Commit

Permalink
-Adding the ability to send key pressed.
Browse files Browse the repository at this point in the history
-Updating the naming for Keycodes
  • Loading branch information
Visic committed Oct 6, 2015
1 parent a9a4332 commit 4f6f005
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 17 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ _ReSharper*/
[Tt]est[Rr]esult*
*.vssscc
$tf*/
PushToGithub.txt
PushToGithub.txt
/CPPUtility.opensdf
/Dist/CPPUtility.dll
/Dist/CPPUtility.jl
/Dist/CPPUtility_Extended.jl
/Dist/keycodes.jl
Binary file modified CPPUtility.sdf
Binary file not shown.
4 changes: 3 additions & 1 deletion CPPUtility/CPPUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ DLLINTERFACE Coord getConsoleCursorPos();
DLLINTERFACE Coord getConsoleDims();
DLLINTERFACE long getLastError();
DLLINTERFACE int clearScreen();
DLLINTERFACE int setConsoleCursorVisibility(int visible);
DLLINTERFACE int setConsoleCursorVisibility(int visible);
DLLINTERFACE unsigned int sendKeyDown(int keycode);
DLLINTERFACE unsigned int sendKeyUp(int keycode);
10 changes: 6 additions & 4 deletions CPPUtility/CPPUtility.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CPPUtility
using KEYCODES
export getkeystate, get_async_key_state, set_console_cursor_pos, get_console_cursor_pos, getlasterror, clearscreen, set_console_cursor_visibility, getconsoledims
using Keycodes
export getkeystate, get_async_key_state, set_console_cursor_pos, get_console_cursor_pos, getlasterror, clearscreen, set_console_cursor_visibility, getconsoledims, sendkeydown, sendkeyup

const dllName = "CPPUtility.dll"

Expand All @@ -9,12 +9,14 @@ immutable Coord
Y::Int16
end

getkeystate(keycode::KEYCODES.KEYCODE) = ccall((:getKeyState, dllName), Int8, (Int32,), keycode)
get_async_key_state(keycode::KEYCODES.KEYCODE) = ccall((:getAsyncKeyState, dllName), Int8, (Int32,), keycode)
getkeystate(keycode::Keycodes.KEYCODE) = ccall((:getKeyState, dllName), Int8, (Int32,), keycode)
get_async_key_state(keycode::Keycodes.KEYCODE) = ccall((:getAsyncKeyState, dllName), Int8, (Int32,), keycode)
set_console_cursor_pos(x::Integer, y::Integer) = ccall((:setConsoleCursorPos, dllName), Int64, (Int16, Int16), x, y)
getlasterror() = ccall((:getLastError, dllName), Int64, ())
clearscreen() = ccall((:clearScreen, dllName), Int32, ())
set_console_cursor_visibility(visible::Bool) = ccall((:setConsoleCursorVisibility, dllName), Int32, (Int32,), Int32(visible))
sendkeydown(keycode::Keycodes.KEYCODE) = ccall((:sendKeyDown, dllName), UInt32, (Int32,), keycode)
sendkeyup(keycode::Keycodes.KEYCODE) = ccall((:sendKeyUp, dllName), UInt32, (Int32,), keycode)

function get_console_cursor_pos()
coord = ccall((:getConsoleCursorPos, dllName), Coord, ())
Expand Down
12 changes: 6 additions & 6 deletions CPPUtility/CPPUtility.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>xcopy /I /Y "$(OutputPath)$(TargetName).dll" "$(SolutionDir)..\..\Game"
xcopy /I /Y "$(ProjectDir)*.jl" "$(SolutionDir)..\..\Game"</Command>
<Command>xcopy /I /Y "$(OutputPath)*.dll" "$(SolutionDir)Dist"
xcopy /I /Y "$(ProjectDir)*.jl" "$(SolutionDir)Dist"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -196,8 +196,8 @@ xcopy /I /Y "$(ProjectDir)*.jl" "$(SolutionDir)..\..\Game"</Command>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PostBuildEvent>
<Command>xcopy /I /Y "$(OutputPath)$(TargetName).dll" "$(SolutionDir)..\..\Game"
xcopy /I /Y "$(ProjectDir)*.jl" "$(SolutionDir)..\..\Game"</Command>
<Command>xcopy /I /Y "$(OutputPath)*.dll" "$(SolutionDir)Dist"
xcopy /I /Y "$(ProjectDir)*.jl" "$(SolutionDir)Dist"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Export|x64'">
Expand All @@ -217,8 +217,8 @@ xcopy /I /Y "$(ProjectDir)*.jl" "$(SolutionDir)..\..\Game"</Command>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PostBuildEvent>
<Command>xcopy /I /Y "$(OutputPath)$(TargetName).dll" "$(SolutionDir)..\..\Game"
xcopy /I /Y "$(ProjectDir)*.jl" "$(SolutionDir)..\..\Game"</Command>
<Command>xcopy /I /Y "$(OutputPath)*.dll" "$(SolutionDir)Dist"
xcopy /I /Y "$(ProjectDir)*.jl" "$(SolutionDir)Dist"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
31 changes: 27 additions & 4 deletions CPPUtility/WindowsAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#include <Windows.h>
#include <stdlib.h>

short getKeyState(int keyCode) {
return GetKeyState(keyCode);
short getKeyState(int keycode) {
return GetKeyState(keycode);
}

short getAsyncKeyState(int keyCode) {
return GetAsyncKeyState(keyCode);
short getAsyncKeyState(int keycode) {
return GetAsyncKeyState(keycode);
}

int setConsoleCursorPos(short x, short y) {
Expand Down Expand Up @@ -51,4 +51,27 @@ int setConsoleCursorVisibility(int visible) {
if(!GetConsoleCursorInfo(hStdOut, &cursorInfo)) return 0;
cursorInfo.bVisible = visible;
return SetConsoleCursorInfo(hStdOut, &cursorInfo);
}

unsigned int sendKeyDown(int keycode) {
KEYBDINPUT keyboardInput;
keyboardInput.wVk = keycode;

INPUT input;
input.ki = keyboardInput;
input.type = INPUT_KEYBOARD;

SendInput(1, &input, sizeof(input));
}

unsigned int sendKeyUp(int keycode) {
KEYBDINPUT keyboardInput;
keyboardInput.wVk = keycode;
keyboardInput.dwFlags = KEYEVENTF_KEYUP;

INPUT input;
input.ki = keyboardInput;
input.type = INPUT_KEYBOARD;

SendInput(1, &input, sizeof(input));
}
2 changes: 1 addition & 1 deletion CPPUtility/keycodes.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module KEYCODES
module Keycodes
@enum KEYCODE k_mbutton = 0x04 k_xbutton1 = 0x05 k_xbutton2 = 0x06 k_back = 0x08 k_tab = 0x09 k_clear = 0x0C k_return = 0x0D k_shift = 0x10 k_control = 0x11 k_menu = 0x12 k_pause = 0x13 k_capital = 0x14 k_final = 0x18 k_escape = 0x1B k_convert = 0x1C k_nonconvert = 0x1D k_accept = 0x1E k_modechange = 0x1F k_space = 0x20 k_prior = 0x21 k_next = 0x22 k_end = 0x23 k_home = 0x24 k_left = 0x25 k_up = 0x26 k_right = 0x27 k_down = 0x28 k_select = 0x29 k_print = 0x2A k_execute = 0x2B k_snapshot = 0x2C k_insert = 0x2D k_delete = 0x2E k_help = 0x2F k_zero = 0x30 k_one = 0x31 k_two = 0x32 k_three = 0x33 k_four = 0x34 k_five = 0x35 k_six = 0x36 k_seven = 0x37 k_eight = 0x38 k_nine = 0x39 k_a = 0x41 k_b = 0x42 k_c = 0x43 k_d = 0x44 k_e = 0x45 k_f = 0x46 k_g = 0x47 k_h = 0x48 k_i = 0x49 k_j = 0x4A k_k = 0x4B k_l = 0x4C k_m = 0x4D k_n = 0x4E k_o = 0x4F k_p = 0x50 k_q = 0x51 k_r = 0x52 k_s = 0x53 k_t = 0x54 k_u = 0x55 k_v = 0x56 k_w = 0x57 k_x = 0x58 k_y = 0x59 k_z = 0x5A k_lwin = 0x5B k_rwin = 0x5C k_apps = 0x5D k_sleep = 0x5F k_numpad0 = 0x60 k_numpad1 = 0x61 k_numpad2 = 0x62 k_numpad3 = 0x63 k_numpad4 = 0x64 k_numpad5 = 0x65 k_numpad6 = 0x66 k_numpad7 = 0x67 k_numpad8 = 0x68 k_numpad9 = 0x69 k_multiply = 0x6A k_add = 0x6B k_separator = 0x6C k_subtract = 0x6D k_decimal = 0x6E k_divide = 0x6F k_f1 = 0x70 k_f2 = 0x71 k_f3 = 0x72 k_f4 = 0x73 k_f5 = 0x74 k_f6 = 0x75 k_f7 = 0x76 k_f8 = 0x77 k_f9 = 0x78 k_f10 = 0x79 k_f11 = 0x7A k_f12 = 0x7B k_f13 = 0x7C k_f14 = 0x7D k_f15 = 0x7E k_f16 = 0x7F k_f17 = 0x80 k_f18 = 0x81 k_f19 = 0x82 k_f20 = 0x83 k_f21 = 0x84 k_f22 = 0x85 k_f23 = 0x86 k_f24 = 0x87 k_numlock = 0x90 k_scroll = 0x91 k_lshift = 0xA0 k_rshift = 0xA1 k_lcontrol = 0xA2 k_rcontrol = 0xA3 k_lmenu = 0xA4 k_rmenu = 0xA5 k_browser_back = 0xA6 k_browser_forward = 0xA7 k_browser_refresh = 0xA8 k_browser_stop = 0xA9 k_browser_search = 0xAA k_browser_favorites = 0xAB k_browser_home = 0xAC k_volume_mute = 0xAD k_volume_down = 0xAE k_volume_up = 0xAF k_media_next_track = 0xB0 k_media_prev_track = 0xB1 k_media_stop = 0xB2 k_media_play_pause = 0xB3 k_launch_mail = 0xB4 k_launch_media_select = 0xB5 k_launch_app1 = 0xB6 k_launch_app2 = 0xB7 k_oem_1 = 0xBA k_oem_plus = 0xBB k_oem_comma = 0xBC k_oem_minus = 0xBD k_oem_period = 0xBE k_oem_2 = 0xBF k_oem_3 = 0xC0 k_oem_4 = 0xDB k_oem_5 = 0xDC k_oem_6 = 0xDD k_oem_7 = 0xDE k_oem_8 = 0xDF k_oem_102 = 0xE2 k_processkey = 0xE5 k_packet = 0xE7 k_attn = 0xF6 k_crsel = 0xF7 k_exsel = 0xF8 k_ereof = 0xF9 k_play = 0xFA k_zoom = 0xFB k_noname = 0xFC k_pa1 = 0xFD k_oem_clear = 0xFE
end
2 changes: 2 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Single out mouse buttons in sendKeyDown and sendKeyUp, they need to be special cased for the windows api
-Consider making sendKeyDown and sendKeyUp take arrays of keys

0 comments on commit 4f6f005

Please sign in to comment.