The Corsair User Forums  

Go Back   The Corsair User Forums > Corsair Product Discussion > Corsair Utility Engine (CUE) 1.x and 2.x > CUE 1.x and 2.x SDK

 
 
Thread Tools Search this Thread Rate Thread Display Modes
  #16  
Old 12-17-2017, 02:04 PM
hastegag hastegag is offline
Registered User
hastegag's PC Specs
 
Join Date: Dec 2016
Location: Northeast US
Posts: 677
POST ID # = 930910
hastegag Reputation: 20
Default

ugh, that was dumb of me, I just struggled through using the ancient version 1.xx posted at the top of the forums, could not find the CorsairRegisterKeypressCallback() function...so now i have the modern one... :)
  #17  
Old 12-17-2017, 02:33 PM
hastegag hastegag is offline
Registered User
hastegag's PC Specs
 
Join Date: Dec 2016
Location: Northeast US
Posts: 677
POST ID # = 930919
hastegag Reputation: 20
Default

The Register callback.cpp solution has what i need. It will be spaghetti with this approach, but should work for me:

if(keyIdStrings.at(keyId) == "CorsairKeyKb_G1")
{
std::cout << keyIdStrings.at(keyId);
//or anything else
}
  #18  
Old 12-17-2017, 07:22 PM
hastegag hastegag is offline
Registered User
hastegag's PC Specs
 
Join Date: Dec 2016
Location: Northeast US
Posts: 677
POST ID # = 930958
hastegag Reputation: 20
Default

So for anyone else looking to do this, and I am sure there are many, I have provided the following:

http://smithany.com/register_callback.exe
which is basically a modified version of the newer example D.A. suggested I pursue earlier:
http://smithany.com/register_callback.cpp

(sorry that's probably a terrible way to go about it, but as i understand c++ doesn't love switch statements based on strings in a straightforward manner - i could probably switch based on the key rather than the string compared keylist at the top...might be better method but I am out of my depth)

Also, my autohotkey that runs along side it is:
http://smithany.com/suitableRemap.ahk

Which so far, although largely untested, appears to not stomp keyboard stuff as I gave it a quick brown fox jumps over the lazy dog and the top rows and fkeys and got no alerts...ymmv and I may have a problem in the future using these reserve keycodes, but it seems to be a working proof of concept that will be helpful for me.
  #19  
Old 12-19-2017, 11:41 AM
hastegag hastegag is offline
Registered User
hastegag's PC Specs
 
Join Date: Dec 2016
Location: Northeast US
Posts: 677
POST ID # = 931165
hastegag Reputation: 20
Default only on release keypress?

If anybody cares, my code was bad as posted and linked above...down and up events were both triggering the fake keypress.

That said, there were two ways to fix, one you could do this hacky thing in AHK:
Code:
global ultraProfile:=0
global noRepeat:=1
SC0C1::
	;MsgBox G1
	if(ultraProfile && !noRepeat){
		Send, stuff
		noRepeat:=!noRepeat
		Sleep,500
	}
	noRepeat:=!noRepeat
Return
SC0EA::
	;MsgBox M10
	ultraProfile:=1
	noRepeat:=0
return
or better yet what appears to work is also check for the boolean in register_callback with the short circuit AND with the keyId (which is also better i assume than my earlier posted character string comparison)
Code:
		if(keyId == CorsairKeyKb_G1 && pressed)
		{
			keybd_event(VK_KANA, 0xC1, 0, 0);
		}
and so on

Last edited by hastegag; 12-21-2017 at 04:06 PM. Reason: typo
  #20  
Old 12-24-2017, 03:04 PM
hastegag hastegag is offline
Registered User
hastegag's PC Specs
 
Join Date: Dec 2016
Location: Northeast US
Posts: 677
POST ID # = 932112
hastegag Reputation: 20
Default switch functionality of Presses of macro keys based on profile

Quick follow up to this, assuming you always have certain keys that are statically lit a certain way, you can tell from the SDK what profile you have currently active by polling a specific key.

Might not seem that helpful, but if you do have macros outside of CUE, it can be a good error checking process to ensure the profile is active if they either work hand in hand or if they might otherwise stomp each other etc.

Below is an excerpt from the register_callback.cpp provided in the SDK, with some basic edits. Looks for all red brightness on the Q key in this example, polled for when G1 is hit:

Code:
		auto ledId = CLK_Q;
		CorsairLedColor ledColor = {ledId, 0, 0, 0};
		CorsairGetLedsColors(1, &ledColor); //fills the rgb above
		if (keyId == CorsairKeyKb_G1 && pressed)//keyIdStrings.at(keyId) == "CorsairKeyKb_G1")
		{
			if (ledColor.r == 255)
			{
				
				keybd_event(VK_CONTROL, 0x11, 0, 0); // PRESS CONTROL
				keybd_event(VK_KANA, 0xC1, 0, 0); // PRESS FUNKY
				keybd_event(VK_CONTROL, 0x11, KEYEVENTF_KEYUP, 0); //KEYEVENTF_KEYUP DWORD FLAG TO RELEASE CTRL
			}
			else
			{
				keybd_event(VK_KANA, 0xC1, 0, 0);
			}
		}
The above would send control + some key recognized elsewhere. I realized I have more than 6 profiles, and since I'd be potentially using modifiers inside of those profiles and recognizing them elsewhere, sending ctrl/shift/alt modified offkeyboard keypresses is not that constructive. Better alternative is to write to a file and read it back in when called to detect for the active profile in CUE. I guess you could pass this through memory, but i'm not sure how to do that other than polling for the PID and then using a consistent offset maybe). Better approach is more or less below:

Code:
#include <fstream>
...
			if (ledColor.r == 255)
			{
				//WRITE to FILE OR MEMORY as you may have more than a half dozen profiles
				std::ofstream myfile;
				myfile.open("Profile.txt");
				myfile << "Default";
				myfile.close();
			}
			else
			{
				keybd_event(VK_KANA, 0xC1, 0, 0);
			}

Refactored code for my purposes at:
http://www.smithany.com/register_callback.cpp

Made a function for outputting the active profile in CUE, but with less lines etc

Last edited by hastegag; 12-24-2017 at 06:21 PM. Reason: better method / code refactored again
  #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: 677
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
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:15 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.