TroisVerites Posted November 13, 2012 Share Posted November 13, 2012 I tried this with scar 3.36 , but it doesn't work with my game X. I use this in other game Z and it work (scar 3.34). I tried the SendInput API (KeyCode=2) in another langage (Python) and it work too with game X. I use the same user account for game and test program. Of course if I try all in notepad, everything is fine. Anyone has an idea ? program New; {$I .\Math.scar} begin WaitRR(5000, 5000); KeyDown('1'); KeyUp('1'); vKeyDown(49); vKeyUp(49); end. Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 13, 2012 Share Posted November 13, 2012 Did you activate the window before sending the keys? Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 13, 2012 Share Posted November 13, 2012 Yeah try doing [scar] program New; {$I .\Math.scar} begin GetClient.Activate; WaitRR(5000, 5000); KeyDown('1'); KeyUp('1'); vKeyDown(49); vKeyUp(49); end.[/scar] Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted November 13, 2012 Author Share Posted November 13, 2012 HI, Scar 3.36 I tried your code , but nothing more. - I used the cross to activate a new client Target ( My game X ) - I run your code with my game X and nothing - I run your code with notepad , Key is sent. - I run my python test ( Sendinput API ) and it works. Any Idea ? Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 13, 2012 Share Posted November 13, 2012 Well, SCAR uses SendInput as well... Can you show me your python code for this? Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 13, 2012 Share Posted November 13, 2012 Maybe with the VK_ [scar]program New; {$I .\Math.scar} begin GetClient.Activate; WaitRR(5000, 5000); KeyDown('1'); KeyUp('1'); vKeyDown(VK_NUMPAD1); vKeyUp(VK_NUMPAD1); end.[/scar] Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted November 14, 2012 Author Share Posted November 14, 2012 For Freddy, #------------------------------------------------------------------------------- # Name: os_win_sendinput # Purpose: # # Author: Fred # # Created: 08/11/2012 # Copyright: (c) Fred 2012 # Licence: <your licence> #------------------------------------------------------------------------------- #!/usr/bin/env python #------------------------------------------------------------------------------- # import #------------------------------------------------------------------------------- from ctypes import * user32 = windll.user32 #------------------------------------------------------------------------------- # import for main #------------------------------------------------------------------------------- import time #------------------------------------------------------------------------------- # #------------------------------------------------------------------------------- # START SENDINPUT TYPE DECLARATIONS PUL = POINTER(c_ulong) class KeyBdInput(Structure): _fields_ = [("wVk", c_ushort), ("wScan", c_ushort), ("dwFlags", c_ulong), ("time", c_ulong), ("dwExtraInfo", PUL)] class HardwareInput(Structure): _fields_ = [("uMsg", c_ulong), ("wParamL", c_short), ("wParamH", c_ushort)] class MouseInput(Structure): _fields_ = [("dx", c_long), ("dy", c_long), ("mouseData", c_ulong), ("dwFlags", c_ulong), ("time",c_ulong), ("dwExtraInfo", PUL)] class Input_I(Union): _fields_ = [("ki", KeyBdInput), ("mi", MouseInput), ("hi", HardwareInput)] class Input(Structure): _fields_ = [("type", c_ulong), ("ii", Input_I)] # END SENDINPUT TYPE DECLARATIONS #------------------------------------------------------------------------------- # Class #------------------------------------------------------------------------------- class win_sendinput: """ win_sendinput is a class for use of the function sendinput. """ #--------------------------------------------------------------------------- # Class constants #--------------------------------------------------------------------------- INPUT_MOUSE = 0 INPUT_KEYBOARD = 1 INPUT_HARDWARE = 2 KEYEVENTF_KEYDOWN = 0 KEYEVENTF_KEYUP = 2 KEYEVENTF_SCANCODE = 8 MOUSEEVENTF_MOVE = 0x0001 MOUSEEVENTF_LEFTDOWN = 0x0002 MOUSEEVENTF_LEFTUP = 0x0004 MOUSEEVENTF_RIGHTDOWN = 0x0008 MOUSEEVENTF_RIGHTUP = 0x0010 MOUSEEVENTF_MIDDLEDOWN = 0x0020 MOUSEEVENTF_MIDDLEUP = 0x0040 MOUSEEVENTF_ABSOLUTE = 0x8000 #--------------------------------------------------------------------------- # Mouse primitive functions for windows- #--------------------------------------------------------------------------- @staticmethod def MouseInputSend(Flag,dx,dy): """ """ extra = c_ulong(0) Inp = Input() Inp.type = win_sendinput.INPUT_MOUSE Inp.ii.mi = MouseInput(dx, dy, 0, Flag, 0, pointer(extra)) Size = sizeof(Inp) user32.SendInput(1, pointer(Inp), sizeof(Inp)) @staticmethod def KeyInputSend_vkey(Flag, Key): """ """ Inp = Input() Inp.type = win_sendinput.INPUT_KEYBOARD Inp.ii.ki.dwFlags = Flag Inp.ii.ki.wVk = Key Size = sizeof(Inp) user32.SendInput(1, pointer(Inp), sizeof(Inp)) @staticmethod def KeyInputSend_ScanCode(Flag, Key): """ """ Inp = Input() Inp.type = win_sendinput.INPUT_KEYBOARD Inp.ii.ki.dwFlags = win_sendinput.KEYEVENTF_SCANCODE | Flag Inp.ii.ki.wScan = Key Size = sizeof(Inp) user32.SendInput(1, pointer(Inp), sizeof(Inp)) #------------------------------------------------------------------------------- # TEST #------------------------------------------------------------------------------- def main(): time.sleep(5.0) # Virtual Key - Key 6 = vkey 0x36 #win_sendinput.KeyInputSend_vkey(win_sendinput.KEYEVENTF_KEYDOWN,0x36) #win_sendinput.KeyInputSend_vkey(win_sendinput.KEYEVENTF_KEYUP,0x36) # Scan Key - Key 6 = Scan code 7 #win_sendinput.KeyInputSend_ScanCode(win_sendinput.KEYEVENTF_KEYDOWN,7) #win_sendinput.KeyInputSend_ScanCode(win_sendinput.KEYEVENTF_KEYUP,7) # Scan Key - Key 1 = Scan code 2 win_sendinput.KeyInputSend_ScanCode(win_sendinput.KEYEVENTF_KEYDOWN,2) win_sendinput.KeyInputSend_ScanCode(win_sendinput.KEYEVENTF_KEYUP,2) if __name__ == '__main__': main() Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 14, 2012 Share Posted November 14, 2012 For Freddy, #------------------------------------------------------------------------------- # Name: os_win_sendinput # Purpose: # # Author: Fred # # Created: 08/11/2012 # Copyright: (c) Fred 2012 # Licence: <your licence> #------------------------------------------------------------------------------- #!/usr/bin/env python #------------------------------------------------------------------------------- # import #------------------------------------------------------------------------------- from ctypes import * user32 = windll.user32 #------------------------------------------------------------------------------- # import for main #------------------------------------------------------------------------------- import time #------------------------------------------------------------------------------- # #------------------------------------------------------------------------------- # START SENDINPUT TYPE DECLARATIONS PUL = POINTER(c_ulong) class KeyBdInput(Structure): _fields_ = [("wVk", c_ushort), ("wScan", c_ushort), ("dwFlags", c_ulong), ("time", c_ulong), ("dwExtraInfo", PUL)] class HardwareInput(Structure): _fields_ = [("uMsg", c_ulong), ("wParamL", c_short), ("wParamH", c_ushort)] class MouseInput(Structure): _fields_ = [("dx", c_long), ("dy", c_long), ("mouseData", c_ulong), ("dwFlags", c_ulong), ("time",c_ulong), ("dwExtraInfo", PUL)] class Input_I(Union): _fields_ = [("ki", KeyBdInput), ("mi", MouseInput), ("hi", HardwareInput)] class Input(Structure): _fields_ = [("type", c_ulong), ("ii", Input_I)] # END SENDINPUT TYPE DECLARATIONS #------------------------------------------------------------------------------- # Class #------------------------------------------------------------------------------- class win_sendinput: """ win_sendinput is a class for use of the function sendinput. """ #--------------------------------------------------------------------------- # Class constants #--------------------------------------------------------------------------- INPUT_MOUSE = 0 INPUT_KEYBOARD = 1 INPUT_HARDWARE = 2 KEYEVENTF_KEYDOWN = 0 KEYEVENTF_KEYUP = 2 KEYEVENTF_SCANCODE = 8 MOUSEEVENTF_MOVE = 0x0001 MOUSEEVENTF_LEFTDOWN = 0x0002 MOUSEEVENTF_LEFTUP = 0x0004 MOUSEEVENTF_RIGHTDOWN = 0x0008 MOUSEEVENTF_RIGHTUP = 0x0010 MOUSEEVENTF_MIDDLEDOWN = 0x0020 MOUSEEVENTF_MIDDLEUP = 0x0040 MOUSEEVENTF_ABSOLUTE = 0x8000 #--------------------------------------------------------------------------- # Mouse primitive functions for windows- #--------------------------------------------------------------------------- @staticmethod def MouseInputSend(Flag,dx,dy): """ """ extra = c_ulong(0) Inp = Input() Inp.type = win_sendinput.INPUT_MOUSE Inp.ii.mi = MouseInput(dx, dy, 0, Flag, 0, pointer(extra)) Size = sizeof(Inp) user32.SendInput(1, pointer(Inp), sizeof(Inp)) @staticmethod def KeyInputSend_vkey(Flag, Key): """ """ Inp = Input() Inp.type = win_sendinput.INPUT_KEYBOARD Inp.ii.ki.dwFlags = Flag Inp.ii.ki.wVk = Key Size = sizeof(Inp) user32.SendInput(1, pointer(Inp), sizeof(Inp)) @staticmethod def KeyInputSend_ScanCode(Flag, Key): """ """ Inp = Input() Inp.type = win_sendinput.INPUT_KEYBOARD Inp.ii.ki.dwFlags = win_sendinput.KEYEVENTF_SCANCODE | Flag Inp.ii.ki.wScan = Key Size = sizeof(Inp) user32.SendInput(1, pointer(Inp), sizeof(Inp)) #------------------------------------------------------------------------------- # TEST #------------------------------------------------------------------------------- def main(): time.sleep(5.0) # Virtual Key - Key 6 = vkey 0x36 #win_sendinput.KeyInputSend_vkey(win_sendinput.KEYEVENTF_KEYDOWN,0x36) #win_sendinput.KeyInputSend_vkey(win_sendinput.KEYEVENTF_KEYUP,0x36) # Scan Key - Key 6 = Scan code 7 #win_sendinput.KeyInputSend_ScanCode(win_sendinput.KEYEVENTF_KEYDOWN,7) #win_sendinput.KeyInputSend_ScanCode(win_sendinput.KEYEVENTF_KEYUP,7) # Scan Key - Key 1 = Scan code 2 win_sendinput.KeyInputSend_ScanCode(win_sendinput.KEYEVENTF_KEYDOWN,2) win_sendinput.KeyInputSend_ScanCode(win_sendinput.KEYEVENTF_KEYUP,2) if __name__ == '__main__': main() The only difference I see between this and SCAR's KeyDown/KeyUp functions is that it uses KEYEVENTF_SCANCODE rather than KEYEVENTF_UNICODE. I will disable unicode by default and add an option to enable this to TSCARWindowClient, so it will use KEYEVENTF_SCANCODE by default. If that doesn't resolve the issue, I don't know what will. Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 14, 2012 Share Posted November 14, 2012 (edited) EDIT: Actually, I think I'm going to add a mode to send VKeys as scancodes instead, that is much more convenient in the system that is currently in place. EDIT2: You can now toggle on the use of scancodes with [wiki=TSCARWindowClient.Scancodes]TSCARWindowClient.Scancodes[/wiki]. I suggest you give that a try when I release 3.37 RC later today. Edited November 14, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted November 14, 2012 Author Share Posted November 14, 2012 Thanks Freddy I tried my python function 'KeyInputSend_vkey' on my game X , but she doesn't work. It seems this game works only with ScanScode to avoid bot. Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 14, 2012 Share Posted November 14, 2012 I'm uploading the release candidate to the repositories right now, so give it about 3-5 minutes and you should be able to get it. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 14, 2012 Share Posted November 14, 2012 That completes the regular keyboard functions. The silent ones would be with using post message, or some method. From my research I have concluded that in order to get around games with security such as XTrap, GameGuard, Punk Puster, and etc. You would need to make your own keyboard driver, and make it so that it works on win xp ~ win 8. This is the 100% way to do it. Otherwise the games can hook certain functions, and prevent you from doing things. They will directly hook the keyboard at a really low level or DirectInput. Then you can't send input to the window, or use post message, it just won't do anything because the keyboard device/driver is being interfaced directly. They are not using any old message they get from send input or post message, or they are blocked totally. Its odd though to me that Mouse functions for SCAR work perfectly on most games. Why is mouse input different here? Isn't it faked too if it is sent using SendInput? How does that work... Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 14, 2012 Share Posted November 14, 2012 That completes the regular keyboard functions. The silent ones would be with using post message, or some method. There's no other method than sending messages... From my research I have concluded that in order to get around games with security such as XTrap, GameGuard, Punk Puster, and etc. You would need to make your own keyboard driver, and make it so that it works on win xp ~ win 8. This is the 100% way to do it. Otherwise the games can hook certain functions, and prevent you from doing things. They will directly hook the keyboard at a really low level or DirectInput. Then you can't send input to the window, or use post message, it just won't do anything because the keyboard device/driver is being interfaced directly. They are not using any old message they get from send input or post message, or they are blocked totally. Windows sends a flag along with input messages that indicates whether it came from an API or a driver, this makes it easy for programs to distinguish between the two. Its odd though to me that Mouse functions for SCAR work perfectly on most games. Why is mouse input different here? Isn't it faked too if it is sent using SendInput? How does that work... I'm not sure why, but I'm guessing that without a keyboard, most of the games that block fake input can be controlled properly. Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted November 15, 2012 Author Share Posted November 15, 2012 HI Freddy With Scar 3.37 and 'TSCARWindowClient(GetClient).Scancodes := True; - The vKeyDown and vKeyUp work fine - Is it the same for KeyUp and KeyDown ? I tried but it doesn t work. Thanks Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted November 15, 2012 Author Share Posted November 15, 2012 Freddy When you say , 'Windows sends a flag along with input messages that indicates whether it came from an API or a driver, this makes it easy for programs to distinguish between the two.' . Could you explain and show us an example or a link ? For LordJashin Yes it is possible to send message in silent mode , but you need to take care because your window game is not on the activated window (foreground). And the Game can detect if his window is the foreground or not. Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 15, 2012 Share Posted November 15, 2012 HI Freddy With Scar 3.37 and 'TSCARWindowClient(GetClient).Scancodes := True; - The vKeyDown and vKeyUp work fine - Is it the same for KeyUp and KeyDown ? I tried but it doesn t work. Thanks No, they still work the same as before, sending unicode characters. I initially intended to change those rather than the VKey functions, but doing so would break or change a lot of existing functionality. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 15, 2012 Share Posted November 15, 2012 (edited) What I don't understand is. Where would you send the messages if the Game uses an API for getting the messages from the keyboard such as Direct Input or XInput? Would you just send them to the window as usual but now you need that flag set to either API or driver. Like...on a chain, how does it go: Keyboard->Driver->Kernal???->Windows System->API or Windows API???->Game/Application I guess my main issue here, is how the messages go around.... Edited November 15, 2012 by LordJashin Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 15, 2012 Share Posted November 15, 2012 What I don't understand is. Where would you send the messages if the Game uses an API for getting the messages from the keyboard such as Direct Input or XInput? Would you just send them to the window as usual but now you need that flag set to either API or driver. Like...on a chain, how does it go: Keyboard->Driver->Kernal???->Windows System->API or Windows API???->Game/Application I guess my main issue here, is how the messages go around.... I have no idea what you're talking about... Also, the kernel is part of windows... The driver is essentially just a bridge between the device and the kernel, as the kernel by itself doesn't know how a keyboard works. Keyboard events are sent asynchronously to the operating system. When this happens an interrupt will push the OS from user mode into kernel mode where the event will be processed. The kernel will then generate a window message that's sent to the foreground window, after which you re-enter user mode. The kernel does also offers methods to get key presses asynchronously, as demonstrated by GetAsyncKeyState. As I mentioned, the OS also stores a flag indicating whether the input came from a driver. As far as I'm aware, this flag isn't sent along with the key in windowmessages, but it is possible to retrieve it through the window API, using, among other things, keyboard hooks. And note that applications can also use keyboard hooks to get keyboard input, rather than relying on window messages. Quote Link to comment Share on other sites More sharing options...