 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
exohaxor Expert Cheater
Reputation: 1
Joined: 02 Sep 2018 Posts: 101
|
Posted: Sun Apr 12, 2020 3:08 pm Post subject: postMessage |
|
|
is there postMessage function so i can send keys to background windows?
i tried sendMessage but it didnt work _________________
hi |
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sun Apr 12, 2020 7:59 pm Post subject: |
|
|
I usually use something like this:
| Code: | function postMessage(hwnd, wMsg, wParam, lParam)
return executeCodeLocalEx("user32.SendMessageA", hwnd, wMsg, wParam, lParam)
end
function FindWindowN(lpClassName, lpWindowName)
return executeCodeLocalEx("user32.FindWindowA", lpClassName, lpWindowName)
end
function FindWindowExAZ(hWnd1, hWnd2, lpsz1, lpsz2)
return executeCodeLocalEx("user32.FindWindowExA", hWnd1, hWnd2, lpsz1, lpsz2)
end
WM_SETTEXT = 0x000C
WM_CLOSE = 0x0010
function test()
local iHwnd = FindWindowN("notepad", 0)
local iHwndChild = FindWindowExAZ(iHwnd, 0, "Edit", 0)
-- postMessage(iHwnd, WM_CLOSE, 0, 0)
postMessage(iHwndChild, WM_SETTEXT, 0, "Hello World!")
end
-- open notepad and test
test() |
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
exohaxor Expert Cheater
Reputation: 1
Joined: 02 Sep 2018 Posts: 101
|
Posted: Mon Apr 13, 2020 5:12 am Post subject: |
|
|
what am i doing wrong?
| Code: |
function postMessage(hwnd, wMsg, wParam, lParam)
return executeCodeLocalEx("user32.SendMessageA", hwnd, wMsg, wParam, lParam)
end
function FindWindowN(lpClassName, lpWindowName)
return executeCodeLocalEx("user32.FindWindowA", lpClassName, lpWindowName)
end
function FindWindowExAZ(hWnd1, hWnd2, lpsz1, lpsz2)
return executeCodeLocalEx("user32.FindWindowExA", hWnd1, hWnd2, lpsz1, lpsz2)
end
WM_SETTEXT = 0x000C
WM_CLOSE = 0x0010
WM_KEYDOWN = 0x0100
function test()
local iHwnd = FindWindowN("notepad", 0)
local iHwndChild = FindWindowExAZ(iHwnd, 0, "Edit", 0)
-- postMessage(iHwnd, WM_CLOSE, 0, 0)
postMessage(iHwndChild, WM_KEYDOWN, VK_KEY_W, 1)
end
-- open notepad and test
test()
|
_________________
hi |
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Apr 13, 2020 7:41 am Post subject: |
|
|
Try open another app that has W key on their menu.
VK_KEY_W is AHK format, I think it must be VK_W.
On your script, you are trying to send pressed W key to notepad window which doesn't have W key notepad menu or sub-menu. So that will effect nothing.
Instead of using WM_COMMAND with sendMessage(), it should be good using post message function.
Example. work with notepad:
| Code: | function FindWindowN(lpClassName, lpWindowName)
return executeCodeLocalEx("user32.FindWindowA", lpClassName, lpWindowName)
end
function PostMessage(hWnd, Msg, wParam, lParam )
return executeCodeLocalEx("user32.PostMessageA", hWnd, Msg, wParam, lParam)
end
function test()
local iHwnd = FindWindowN("notepad", 0)
PostMessage(iHwnd, 0x0111, 0x0005, 0x0) -- Will open submenu Page Setup in notepad app.
-- 0x0111 = notepad menu 'File'
-- 0x0005 = notepad sub-menu File -> Page Setup
end
test()
|
Conclusion:
- The key command is different for each application.
- Keep looking or search for keycode parameters use with user32.dll sendMessage and PostMessage.
I don't know if there is simple way to do this with pure CE Lua functions. _________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
exohaxor Expert Cheater
Reputation: 1
Joined: 02 Sep 2018 Posts: 101
|
Posted: Mon Apr 13, 2020 12:02 pm Post subject: |
|
|
sorry to bump again but how can i use SendInput in CE?
i found this code for c++
| Code: |
#define WINVER 0x0500
#include <windows.h>
using namespace std;
int main()
{
//Structure for the keyboard event
INPUT ip;
Sleep(5000);
//Set up the INPUT structure
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.wVk = 0; //We're doing scan codes instead
ip.ki.dwExtraInfo = 0;
//This let's you do a hardware scan instead of a virtual keypress
ip.ki.dwFlags = KEYEVENTF_SCANCODE;
ip.ki.wScan = 0x1E; //Set a unicode character to use (A)
//Send the press
SendInput(1, &ip, sizeof(INPUT));
//Prepare a keyup event
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
return 0;
}
|
but how can i set input structure etc in lua _________________
hi |
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1531
|
Posted: Mon Apr 13, 2020 2:48 pm Post subject: |
|
|
| exohaxor wrote: |
but how can i set input structure etc in lua |
Maybe like this,
| Code: | function Pass()
input=""
input = inputQuery(mi.Caption, "Please enter valid password.", input)
if input=="2545" then
print("Done ", input)
else
Print("None ", input)
end
end
Htky=createHotkey(Pass, VK_F8) |
_________________
|
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Apr 13, 2020 7:02 pm Post subject: |
|
|
| exohaxor wrote: | sorry to bump again but how can I use SendInput in CE?
but how can i set input structure etc in lua |
You might considering:
https://github.com/michaelnoonan/inputsimulator _________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25813 Location: The netherlands
|
Posted: Tue Apr 14, 2020 12:24 am Post subject: |
|
|
use a memorystream object to setup the structure _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
exohaxor Expert Cheater
Reputation: 1
Joined: 02 Sep 2018 Posts: 101
|
Posted: Tue Apr 14, 2020 3:06 am Post subject: |
|
|
isnt that c#?
i want to do it in cheat engine _________________
hi |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25813 Location: The netherlands
|
Posted: Tue Apr 14, 2020 5:08 am Post subject: |
|
|
sendinput sends to the foreground window
which is the same a keyDown/keyUp and keyPress in ce's lua (which also calls sendinput) _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Tue Apr 14, 2020 7:15 am Post subject: |
|
|
| exohaxor wrote: | | i want to do it in cheat engine |
Here examples using CE Lua script to send keys stroke to specific app. In this sample I use window notepad:
1. Adapting functions from WIN API (FindWindowA, SetForegroundWindow, keybd_event)
| Code: | function FindWindowA(lpClassName, lpWindowName)
return executeCodeLocalEx("user32.FindWindowA", lpClassName, lpWindowName)
end
function SetForegroundWindowA(hWnd)
return executeCodeLocalEx("user32.SetForegroundWindow", hWnd)
end
function KeyboardEvent(bVk, bScan, dwFlags, dwExtraInfo)
return executeCodeLocalEx("user32.keybd_event", bVk, bScan, dwFlags, dwExtraInfo)
end
KEYEVENTF_KEYUP = 0x2
VK_MENU = 0x12
function keybind() -- example to open 'File Menu' on notepad window
local target = 'notepad'
gamewindow = SetForegroundWindowA(FindWindowA(target,0)) -- focus to notepad window
KeyboardEvent(VK_MENU, 0, 0, 0) -- press ALT ley
KeyboardEvent(VK_F, 0, 0, 0) -- press F key
KeyboardEvent(VK_F, 0, KEYEVENTF_KEYUP, 0) -- release F key
KeyboardEvent(VK_MENU, 0, KEYEVENTF_KEYUP, 0) -- release ALT key
end
-- test : open notepas first
keybind() |
2. Using pure CE Lua functions
| Code: | -- test open note File Menu
ps1 = 'start notepad.exe'
p1 = os.execute(ps1)
sleep(1000)
openProcess('notepad.exe')
w=getWindow(getForegroundWindow(), GW_HWNDFIRST)
pid=getOpenedProcessID()
while w and (w~=0) do
if (getWindowProcessID(w)==pid) and (executeCodeLocal("IsWindowVisible",w)~=0) then
keyDown(VK_MENU)
keyDown(VK_F)
sleep(100)
keyUp(VK_MENU)
keyUp(VK_F)
end
w=getWindow(w, GW_HWNDNEXT)
end
|
3. Alternative, write a vbscript and then call it from CE
vbscript example:
| Code: | Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad.exe"
WshShell.AppActivate "Notepad"
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "abc"
WshShell.SendKeys "{CAPSLOCK}"
WshShell.SendKeys "def" |
Save that script as a vbs file, i.e: mykeybind.vbs and call it from CE Lua:
| Code: | | os.execute([path to vbs file]..'\\mykeybind.vbs') |
If you want using sendInput WIN API then you need generated the structure of pInputs first (google is your friend), but if must adapting to CE Lua function, should be like this:
| Code: | function SendInputA(cInputs, pInputs, cbSize)
return executeCodeLocalEx("user32.SendInput", cInputs, pInputs, cbSize)
end |
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|