Jump to content
A-man

Key combos (Ctrl+Shift+Alt+C)

Recommended Posts

I'm trying to write a macro to enter a list of cheats in to Sim City 3000. I can get it to type a message after I've opened the cheat window, but I can't get the script to do Ctrl+Shift+Alt+C prior to entering the cheat. Here is what I have:

program SimCity3000;

begin
 wait(1000);
 keydown(VK_CONTROL) ;
 keydown(VK_SHIFT);
 keydown(VK_F5); // there is no VK_ALT?
 keydown('c');
 wait(1000);
 TypeText('Pay tribute to your king');  
end.

 

As I said, TypeText works as expected, but there is no VK_ALT, so I tried VK_F5, which also doesn't work. Can anyone help?

Link to comment
Share on other sites

I'm trying to write a macro to enter a list of cheats in to Sim City 3000. I can get it to type a message after I've opened the cheat window, but I can't get the script to do Ctrl+Shift+Alt+C prior to entering the cheat.

As I said, TypeText works as expected, but there is no VK_ALT, so I tried VK_F5, which also doesn't work. Can anyone help?

 

In my experience SCAR's input functions for the keyboard have had trouble with some games and do not work at all. E.g. some games TypeText works, but not VKEYs. So I have started work on a library (plugin) that gives SCAR some more keyboard functions from Win32 api. One of which is called, SendInput. Which I heard can be configured to send keys to any game almost. But the one that worked for me for the game I was trying to get Vkeys to work on was called Keybd_Input or something similar. Both are documented on MSDN.

 

I will release a very undeveloped version when I get the time too. And I'll put keybd_input back in it, because I took it out of the plugin to try to just use SendInput because on MSDN it says keybd_input is "obsolete".

 

 

Here is my testing file for SCAR's keyboard input functions that I extensively tested on the game I play:

 

[scar]

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Testing Keyboard Functions

For testing with applications

By: LordJashin

Last Modified: 9/30/2012

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}

 

program KeyboardFunctionTesting;

 

const

WindowTitle = 'Notepad';

 

TestTyping = True;

TextToType = 'Test';

 

TestHotKeyPressing = True;

VirtualHotKey = VK_NUMPAD0; // Virtual Key codes, google it

KeyDownUpHotKey = 8; // Look below, 8 is backspace

 

TimeBtwnTests = 1000; // In miliseconds e.g. 1000 = 1 second

 

{ If you want BACKSPACE then find it in quotes and get the number in that line

which is 8. Now put that for the Constants KeyDownUpHotKey = 8;

Thanks to nemolorn, I think he had the post that had these

 

'BACKSPACE' :Keydown(8);

'TAB' :Keydown(9);

'ENTER' :Keydown(13);

'SHIFT' :Keydown(16);

'ALT' :Keyup(18);

'CAPS LOCK' :Keydown(20);

'CAPS' :Keydown(20);

'CAPSLOCK' :Keydown(20);

'ESC' :Keydown(27);

'SPACEBAR' :Keydown(32);

'SPACE' :Keydown(32);

'PAGE UP' :Keydown(33);

'PAGEUP' :Keydown(33);

'PG UP' :Keydown(33);

'PGUP' :Keydown(33);

'PAGE DOWN' :Keydown(34);

'PAGEDOWN' :Keydown(34);

'PG DOWN' :Keydown(34);

'PGDOWN' :Keydown(34);

'END' :Keydown(35);

'HOME' :Keydown(36);

'LEFT' :Keydown(37);

'UP' :Keydown(38);

'RIGHT' :Keydown(39);

'DOWN' :Keydown(40);

'PRINTSCREEN' :Keydown(44);

'PRTSCRN' :Keydown(44);

'PRINT SCREEN' :Keydown(44);

'PRT SCR' :Keydown(44);

'INSERT' :Keydown(45);

'COPY' : Keydown(67);

'PASTE' : Keydown(86);

'CUT' :Keydown(88);

'WINDOWS' :Keydown(92);

'START' :Keydown(92);

'UNDO' :Keydown(90);

'F1' :Keydown(112);

'F2' :Keydown(113);

'F3' :Keydown(114);

'F4' :Keydown(115);

'F5' :Keydown(116);

'F6' :Keydown(117);

'F10' :Keydown(121);

'NUMLOCK' :Keydown(144);

'NUM LOCK' :Keydown(144);

'NUM' :Keydown(144);

}

 

var

Client: TSCARWindowClient;

IsClientCreated: Boolean;

 

function SetupWindow(Title: string; CaseSensitive, PartialMatch: Boolean): Boolean;

var

arr: THwndArray;

B: Boolean;

begin

Result := False;

arr := FindWindowsEx(GetDesktopWindow, Title, '', false, CaseSensitive, PartialMatch);

if Length(arr) < 1 then Exit;

try

Client := TSCARWindowClient.Create(arr[0]);

Except

B := True;

finally

if not B then

Result := True;

end;

if Result then

IsClientCreated := True;

end;

 

procedure SetupClient(BringToFront: Boolean);

begin

if not SetupWindow(WindowTitle, false, true) then

begin

WriteLn('Failed to Find Application Window! Terminating script!');

TerminateScript;

end;

if BringToFront then

Client.Activate;

end;

 

procedure ShowBox(Text: string);

begin

WriteLn(Text);

wait(TimeBtwnTests);

GetApplication.BringToFront;

GetApplication.MessageBox(Text, 'Alert!', 0);

Client.Activate;

end;

 

procedure TestKeyboardTyping(Text: string);

var

i: Integer;

begin

ShowBox('Testing TypeText');

TypeText(Text);

ShowBox('Testing TypeTextEx, Use Delays, and Numpad');

TypeTextEx(Text, True, True);

ShowBox('Testing PressKey, for all the text');

for i := 1 to Length(Text) do

PressKey(Text);

wait(700);

ShowBox('Testing PressKeyEx, for all the text, with a 300 interval');

for i := 1 to Length(Text) do

PressKeyEx(Text, 300);

ShowBox('Testing PressVKey, for all the text');

for i := 1 to Length(Text) do

PressVKey(CharToVKey(Text));

ShowBox('Testing PressVKeyEx, for all the text, with a 300 interval');

for i := 1 to Length(Text) do

PressVKeyEx(CharToVKey(Text), 300);

ShowBox('Testing KeyDown and KeyUp for all the text, with 150 wait inbetween');

for i := 1 to Length(Text) do

begin

KeyDown(Text);

wait(150);

KeyUp(Text);

end;

ShowBox('Testing VKeyDown and VKeyUp for all the text, with 150 wait inbetween');

for i := 1 to Length(Text) do

begin

VKeyDown(CharToVKey(Text));

wait(150);

VKeyUp(CharToVKey(Text));

end;

end;

 

procedure TestKeyboardHotkeys;

begin

ShowBox('Testing PressVKey with VirtualHotKey');

PressVKey(VirtualHotKey);

ShowBox('Testing VKeyDown and VKeyUp with VirtualHotKey');

VKeyDown(VirtualHotKey);

VKeyUp(VirtualHotKey);

ShowBox('Testing PressKey with KeyDownUpHotKey');

PressKey(Byte(KeyDownUpHotKey));

ShowBox('Testing KeyDown and KeyUp with KeyDownUpHotKey');

KeyDown(Byte(KeyDownUpHotKey));

KeyUp(Byte(KeyDownUpHotKey));

end;

 

procedure MainLoop;

var

T: Integer;

begin

T := GetSystemTime;

SetupClient(true);

if TestTyping then

TestKeyboardTyping(TextToType);

if TestHotKeyPressing then

TestKeyboardHotkeys;

WriteLn('Successfully ran in (' + IntToStr(GetSystemTime - T) + ' ms)');

end;

 

procedure ScriptTerminate;

begin

if IsClientCreated then

Client.Free;

end;

 

begin

ClearDebug;

MainLoop;

end.

[/scar]

 

555 post! Also a "problem" I noticed is that VKEY's. Usually always put in lowercase. So like PressVKey(CharToVKey('A')); Will type the letter a, and not in caps.

Edited by LordJashin
Link to comment
Share on other sites

There's no "from Delphi"... You're referring to the Win32 API, which is what SCAR's core API uses... All of SCAR 3.35's functions call the SendInput API as keybd_input is deprecated.

 

I didn't know what SCAR used for its keyboard functions. I should have guessed maybe. My bad on the from delphi part. From delphi that gets it from the Win32 api :D. Then just use <s></s> strikeout tag on the first part of that sentence.

 

Still though I think there is different ways to use SendInput api that would work better with "some" games. Idk for sure yet exactly. But I have read around and you can put different scan codes in? I just found it weird that Keybd_input worked for this game I play that didn't allow the VKeys. I will experiment around, and make some functions in the plugin for these things...some might find similar results with that keybd_input function with their games.

Link to comment
Share on other sites

Still though I think there is different ways to use SendInput api that would work better with "some" games. Idk for sure yet exactly. But I have read around and you can put different scan codes in? I just found it weird that Keybd_input worked for this game I play that didn't allow the VKeys. I will experiment around, and make some functions in the plugin for these things...some might find similar results with that keybd_input function with their games.
Well mate, that is so true... It indeed would be pretty nice to have multiple types of key/mouse input methods built-in to SCAR, where scripter's could decide which ones to use (depending what each game accepts obviously).. Default one's would be the current ones that are in use. BUT, not sure if it's even possible, so this is ONLY me thinking/dreaming out loud right now, haha. :D

 

Ahhhh, I am still dreaming about having those kernel mode drivers in SCAR (someday in future) for emulating mouse and keyboard actions (hopefully in both projects - Divi & Titan) They would make SCAR work for 99%, if not 100%(!), of the games around. Too bad adding em in isn't really the smallest or easiest task there is - at all... What I have heard, they are plenty and plenty of work. :(

 

*Stops dreaming and gets back to scripting*

Link to comment
Share on other sites

I didn't know what SCAR used for its keyboard functions. I should have guessed maybe. My bad on the from delphi part. From delphi that gets it from the Win32 api :D. Then just use <s></s> strikeout tag on the first part of that sentence.

 

Still though I think there is different ways to use SendInput api that would work better with "some" games. Idk for sure yet exactly. But I have read around and you can put different scan codes in? I just found it weird that Keybd_input worked for this game I play that didn't allow the VKeys. I will experiment around, and make some functions in the plugin for these things...some might find similar results with that keybd_input function with their games.

 

There is 2 ways you can send keys with SendInput. You can send virtual keys and scancodes. The VKeyX functions do the first, the KeyX functions do the latter.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...