Page 1 of 1

Tutorial:App filter script

Posted: 22 Dec 2015, 12:23
by Buzzin
print('Version: ' .. lmc.version)
--lmc.minimizeToTray = true
--lmc_minimize()

lmc_print_devices()
lmc_device_set_name('kb2', 'D0E7FD3')
lmc_set_handler('kb2',function(button, direction)
tt=lmc_get_window_title()
print(tt)
if (direction == 1) then return end -- ignore down

if (string.match(tt, "Chrome")) then
if (button == 97) then lmc_send_keys("^{TAB}")
elseif (button == 98)then lmc_send_keys("^+{TAB}")
else print('Not yet assigned: ' .. button)
end
else
end

if (string.match(tt, "lua")) then
if (button == 97) then lmc_send_keys("1")
elseif (button == 98)then lmc_send_keys("2")
else print('Not yet assigned: ' .. button)
end
else
end
end

Re: Tutorial:App filter script

Posted: 22 Dec 2015, 12:37
by Buzzin
well there is a problem
you can only use the same key as different apps filter shortcut
but you cnat set 1 key has global shortcut and a app filter shortcut both ,
i will try to figure this out latter

Re: Tutorial:App filter script

Posted: 22 Dec 2015, 12:52
by Buzzin
print('Version: ' .. lmc.version)
--lmc.minimizeToTray = true
--lmc_minimize()

lmc_print_devices()
lmc_device_set_name('kb2', 'D0E7FD3')
lmc_set_handler('kb2',function(button, direction)
tt=lmc_get_window_title()
print(tt)
if (direction == 1) then return end -- ignore down

if (string.match(tt, "Chrome")) then
appf=1
if (button == 97) then lmc_send_keys("^{TAB}")
elseif (button == 98)then lmc_send_keys("^+{TAB}")
else print('Not yet assigned: ' .. button)
end
else
appf=0
end

if (string.match(tt, "lua")) then
appf =1
if (button == 97) then lmc_send_keys("1")
elseif (button == 98)then lmc_send_keys("2")
else print('Not yet assigned: ' .. button)
end
else
appf =0
end

if (appf ==0) then
if (button == 97) then lmc_send_keys("^+{F11}")
elseif (button == 98)then lmc_send_keys("2")
else print('Not yet assigned: ' .. button)
end
else
end


end)


problem sovled!!!!
checkout the "appf"

Re: Tutorial:App filter script

Posted: 21 Mar 2017, 08:59
by csadi0011
The idea was good, but You did a mistake.
Use Your code like this:

Code: Select all

if (string.match(tt, "Chrome")) then
   appf=1
   if (button == 97) then lmc_send_keys("^{TAB}")
   elseif (button == 98)then lmc_send_keys("^+{TAB}")
   else appf=0
   end
end   

Re: Tutorial:App filter script

Posted: 12 Apr 2017, 02:56
by MrAndreas
Detecting apps based on their captions is not very reliable. Other macro software that comes with gaming keyboards/mice, all use the executable to define such filters, i.e., the user browses to the executable to select which one that applies in each instance and the software then evaluates the path of the foreground window to see if they match.

Re: Tutorial:App filter script

Posted: 12 Apr 2017, 03:05
by MrAndreas
Not sure how to do this in LUA, but here's how it's done in C++ (from http://stackoverflow.com/questions/2397 ... f-a-window)...

while(true)
{
Sleep(250);//reduce cpu usage
CHAR __name[MAX_PATH];//name buffer
HWND hwnd;//window handle
DWORD pid;//process pid
hwnd=FindWindow(NULL,NULL);//find any window
PROCESSENTRY32 entry;//process structure containing info about processes
entry.dwSize=sizeof(PROCESSENTRY32);
HANDLE snapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);//get processes
if(hwnd!=0)
{
GetWindowThreadProcessId(hwnd,&pid);//get found window pid
}
if (Process32First(snapshot,&entry)==TRUE)//start listing processes
{
while (Process32Next(snapshot,&entry)==TRUE)
{
if (stricmp(entry.szExeFile,"explorer.exe")==0)
{
if(pid!=entry.th32ProcessID)//if found window pid is explorers one, skip it
{
HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid);//open processusing PROCESS_ALL_ACCESS to get handle
if(hProcess!=NULL)
{
GetModuleFileNameEx(hProcess,NULL,__name,MAX_PATH);//get executable path
cout<<"Found: "<<__name<<endl;
}
}
}
}
}

Would be great to have a function callable from within LuaMacros that would return the active window's full path since this is a very useful function to have for a macro software such as LuaMacro.

Re: Tutorial:App filter script

Posted: 12 Apr 2017, 07:54
by admin
You can create feature request issue here: https://github.com/me2d13/luamacros/issues
Better for tracking...