Tutorial:App filter script

Documentation. First post is always kind of manual page, being continuously updated by author. Following posts are discussion about the topic.
Post Reply
Buzzin
Posts: 8
Joined: 22 Dec 2015, 12:20

Tutorial:App filter script

Post by Buzzin » 22 Dec 2015, 12:23

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

Buzzin
Posts: 8
Joined: 22 Dec 2015, 12:20

Re: Tutorial:App filter script

Post by Buzzin » 22 Dec 2015, 12:37

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

Buzzin
Posts: 8
Joined: 22 Dec 2015, 12:20

Re: Tutorial:App filter script

Post by Buzzin » 22 Dec 2015, 12:52

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"

csadi0011
Posts: 3
Joined: 18 Mar 2017, 11:09

Re: Tutorial:App filter script

Post by csadi0011 » 21 Mar 2017, 08:59

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   

MrAndreas
Posts: 6
Joined: 12 Apr 2017, 02:37

Re: Tutorial:App filter script

Post by MrAndreas » 12 Apr 2017, 02:56

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.

MrAndreas
Posts: 6
Joined: 12 Apr 2017, 02:37

Re: Tutorial:App filter script

Post by MrAndreas » 12 Apr 2017, 03:05

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.

admin
Site Admin
Posts: 535
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Tutorial:App filter script

Post by admin » 12 Apr 2017, 07:54

You can create feature request issue here: https://github.com/me2d13/luamacros/issues
Better for tracking...
Petr Medek
LUAmacros author

Post Reply