Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

new to programming, c++ and ahk


  • Please log in to reply
3 replies to this topic
place
  • Members
  • 34 posts
  • Last active: Oct 02 2014 04:43 AM
  • Joined: 18 Jan 2011

hey, so i started to feed my programming curiosity a few years ago with ahk and lately i've been teaching myself c++ and i'm wondering how the Send commands in ahk work and if there are simple ways in c++ to do something similar.

 

for example:

 

in ahk i might do this

SendInput, {ENTER} Hello {ENTER}

 

how would i do something similar with c++? preferably using as small amount of code as possible.



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
you could look through the AHK source and see how it does everything

for SendInput, maybe it calls this win api function?
http://msdn.microsof...esktop/ms646310(v=vs.85).aspx

place
  • Members
  • 34 posts
  • Last active: Oct 02 2014 04:43 AM
  • Joined: 18 Jan 2011

yeah, i've been looking at that trying to understand it but so far i can't seem to work out how to make a simple function that will make the INPUT object to hold the keys i want to send. i can get it to work with just single letters or buttons like ctrl or enter, but i can't find a solution to making a function like maybe CreateInput("these keys {enter}"); that would then make the INPUT class object and then send it through win API SendInput.



HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Here is something to play with wink.png

#Include <_Struct>
KEYEVENTF_SCANCODE:=0x8,KEYEVENTF_KEYUP:=0x2
INPUT_KEYBOARD:=1
INPUT := "DWORD type,{MOUSEINPUT mi;KEYBDINPUT ki;HARDWAREINPUT hi}"
MOUSEINPUT :=  "LONG dx;LONG dy;DWORD mouseData;DWORD dwFlags;DWORD time;ULONG_PTR dwExtraInfo"
KEYBDINPUT :=  "WORD wVk;WORD wScan;DWORD dwFlags;DWORD time;ULONG_PTR dwExtraInfo"
HARDWAREINPUT := "DWORD uMsg;WORD wParamL;WORD wParamH"
MyInput:=new _Struct("Input[18]")
Loop 18
  MyInput[A_Index].type:=INPUT_KEYBOARD,MyInput[A_Index].ki.dwFlags:=KEYEVENTF_SCANCODE|(Mod(A_Index,2)?0:KEYEVENTF_KEYUP)
Keys:="Enter|Space|H|a|l|l|o|Space|Enter"
Loop,Parse,Keys,|
  MyInput[A_Index*2-1].ki.wScan := MyInput[A_Index*2].ki.wScan := GetKeySC(A_LoopField)
DllCall("SendInput","UInt",18,"PTR",MyInput[],"UInt",sizeof(Input))