Jump to content
Suppels

KeyDown Help

Recommended Posts

Hey I'm new to scar and I've been searching google constantly on how to do this but can't find anything up to date.

Basically I want to make it so if F8 is pressed the script terminates.

Here's the part that doesn't seem to work

 

if KeyDown(VK_F8) then

 

Everytime I try to execute the script it says type mismatch, anyone know what the problem might be?

Cheers

Link to comment
Share on other sites

oh ok cheers, would I need to check if it's true or anything because I've put the code in and when I press F8 nothing happens.

 

begin  
 RD := 0;
 RN := 100; //Change 1 to the number of times you wish to loop 
 if GetKeyState(VK_F8) then
 begin
 TerminateScript;
 gold:= count * 105000;
 exp:= count2 * 21000;
 RD:= RD + 1
 label1stuff := ('Gold Earned     -     ' + IntToStr(gold))
 label2stuff := ('Exp Earned      -     ' + IntToStr(exp))
 label3stuff := ('Runs Done       -     ' + IntToStr(RD) + '/' + IntToStr(RN))
 Wait(50);
 Form1_1_SafeInit;
 end else
 for R := 1 to RN do
 begin                                                                
 Thieve;
 Wait(100)
 ShopKeeper;
 Wait(100);
 SellSlot28;
 Wait(100);
 CloseShop;
 Wait(100);
 MoveSlot28;
 Wait(1000)
 end;
end;

Link to comment
Share on other sites

[scar]if GetKeyState(VK_F8) then[/scar]

Is the same thing as:

[scar]if GetKeyState(VK_F8) = True then[/scar]

 

However, you have to loop it, you're just checking it a single time and then the script stops. It doesn't wait for you to press the key or anything.

Link to comment
Share on other sites

If the script has nothing else to do, you could also make something like this:

[scar] x := 1;

While (x = 1) do

begin

Wait(100);

CheckThingy;

end;[/scar]

 

Checks the key 10 times a second, so you'll have to press the key for at least 100ms to be sure it gets it. It's not clean, but I try to write working code and clean it up at the end. Tried it the other way around (clean it first, then write it), doesn't work and gives a lot of frustration :P

 

 

I don't want to topic hijack, but since I've encountered a problem related to this topic, I'd like to post it here.

If I want to press the P key, I could use KeyDown(80); Wait(100); KeyUp(80);. Why oh why am I getting a type mismatch here? The VK_KEY_P has 0x50 (80 in dec).

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...