View Single Post
  #21  
Old 05-03-2018, 10:33 PM
hastegag hastegag is offline
Registered User
hastegag's PC Specs
 
Join Date: Dec 2016
Location: Northeast US
Posts: 896
POST ID # = 953222
hastegag Reputation: 20
Default

Not sure if anyone cares, but I finally figured out how to get AutoHotkey to read from a memory address to avoid hitting the harddrive a million extra times a year to talk from CPP to Autohotkey without writing a custom DLL that's registered (think that works too). There are a million examples out there, but I swear I was doing everything correctly and tried a hundred different ways and it just wasn't working reliably, but the below works:

Example below:
Code:
global profilePointer:=0
;other code
ReadMemory(MADDRESS,PID)
{
	VarSetCapacity(MVALUE,4,0)
	ProcessHandle := DllCall("OpenProcess", "Int", 24, "Char", 0, "UInt", PID, "UInt")
	DllCall("ReadProcessMemory", "UInt", ProcessHandle, "Ptr", MADDRESS, "Ptr", &MVALUE, "Uint",4)
	Loop 4
	result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
	return, result
}
ProfileName(readNumber)
{
	sendBackProfileName:=""
	if(readNumber=0)
	{
		sendBackProfileName:="Default"
	}
	if(readNumber=1)
	{
		sendBackProfileName:="UltraMod"
	}
	if(readNumber=2)
	{
		sendBackProfileName:="Sketchup"
	}
	if(readNumber=3)
	{
		sendBackProfileName:="ACrucial***"
	}
	if(readNumber=4)
	{
		sendBackProfileName:="Dreamweaver"
	}
	if(readNumber=5)
	{
		sendBackProfileName:="Outlook"
	}
	if(readNumber=6)
	{
		sendBackProfileName:="Word"
	}
	if(readNumber=7)
	{
		sendBackProfileName:="Photoshop"
	}
	if(readNumber=8)
	{
		sendBackProfileName:="Bridge"
	}
	if(readNumber=9)
	{
		sendBackProfileName:="Illustrator"
	}
	if(readNumber=10)
	{
		sendBackProfileName:="Excel"
	}
	return sendBackProfileName
}
getCurProfile()
{
	Process, Exist, register_callback.exe
	PID:=ErrorLevel
	if(profilePointer=0)
	{
		FileRead, profilePointer, C:\CUESDK\examples\register_callback\x64\Release\Profile.txt
		;MsgBox here? ;insurance on writes
	profilePointer := "0x"+profilePointer ;frontloaded zeros are ok but need to register string as hex
	}
	Return ProfileName(ReadMemory(profilePointer,PID))
}
;othercode
SC0C1::
	;MsgBox G1
	profile := getCurProfile()
	if(profile == "Photoshop"){
		Click 390,42 ;Align Top G1
	}
Return
^SC0C1::
	;MsgBox Ctrl G1
        ;do something else
Return
alongside
www.smithany.com/register_callbackImproved.cpp

A lot to fix still, need to figure out how to clock how long something was depressed and figure in a faux repeat rate for G and M keys, thinking the Chrono include can clock the time between one thing and another.

Also need to maybe setup a side profile polling periodically even if no key is pressed if I end up toying with some RGB integration (not a priority for me atm, as I dont currently have a lot of supporting non corsair hardware tho)

Last edited by hastegag; 05-04-2018 at 06:57 PM. Reason: Important correction / clarification in AHK code