Esc/Pause after a certain time

Discussion in 'Plugins' started by Uff, Feb 11, 2016.

  1. Uff

    Uff Registered

    Joined:
    Oct 5, 2010
    Messages:
    279
    Likes Received:
    51
    Hi guys, I would like to create a plugin that puts the game on pause after a certain amount of time. In the UpdateScoring function I managed to get the current race time using the info.mCurrentET value; I then tried to emulate a Esc or P keyboard stroke using the keybd_event() function, but to no avail: the game never pauses nor shows the Esc menu.

    Is it possible to send such input to the sim or does the game ignores these kind of emulated inputs? I also tried to send the mCurrentEt to a server I wrote: it basically received the value and emulated the keystroke, but also in this case I don't get any result. Do you have any idea?
     
  2. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    7,407
    Likes Received:
    3,095
    'Pause' is one of the recognised HW controls, and since it's not a 'driving control' you should probably be able to use it.

    Return true from HasHardwareInputs(), then in CheckHWControl() test for "Pause" (and/or "AlternateEsc" if you want that), and if that test passes then set fRetVal to 1.0 and return true. (note fRetVal is a double; I think the template may have that correct now, but it's had a couple of leftover floats in the past so I'd check it)

    Worth a shot :)

    *Here's a list of HW controls I generated back in build 930, if anyone's interested (remember any driving controls can only be read):

    Code:
    Throttle
    Brake
    SteerLeft
    SteerRight
    ShiftUp
    ShiftDown
    Neutral
    ClutchIn
    TCOverride
    LaunchControl
    SpeedLimiter
    BiasForward
    BiasRearward
    IncrementBoost
    DecrementBoost
    TemporaryBoost
    PowerDemand
    IncrementFrontAntiSway
    DecrementFrontAntiSway
    IncrementRearAntiSway
    DecrementRearAntiSway
    Gear_R
    Gear_1
    Gear_2
    Gear_3
    Gear_4
    Gear_5
    Gear_6
    Gear_7
    Gear_8
    Gear_9
    Ignition
    Starter
    Horn
    Headlights
    Handfrontbrake
    Handbrake
    FrontFlap
    RearFlap
    Wipers
    ToggleAIControl
    DriverHotSwap
    PassengerSelect
    DisplayMode
    PitRequest
    PitMenuUp
    PitMenuDown
    PitMenuIncrementValue
    PitMenuDecrementValue
    LookLeft
    LookRight
    RearLook
    DisplayVehicleLabels
    InstantReplay
    Pause
    RestartRace
    ToggleFreeLook
    ZeroFreeLook
    LookUp
    LookDown
    LookRollLeft
    LookRollRight
    AdjustSeatFore
    AdjustSeatAft
    AdjustSeatUp
    AdjustSeatDown
    IncreaseVerticalFOV
    DecreaseVerticalFOV
    ToggleMirror
    ToggleHUDStats
    ToggleHUDTach
    ToggleHUDMFD
    ToggleOverlays
    RealtimeChat
    QuickChat01
    QuickChat02
    QuickChat03
    QuickChat04
    QuickChat05
    QuickChat06
    QuickChat07
    QuickChat08
    QuickChat09
    QuickChat10
    QuickChat11
    QuickChat12
    Screenshot
    TimeAcceleration
    Framerate
    CPUTime
    AlternateEsc
    SteeringHelp
    OppositeLock
    BrakingHelp
    StabilityControl
    SpinRecovery
    Invulnerability
    AutoShifting
    TractionControl
    AntiLockBrakes
    AutoPit
    AutoClutch
    SharedMemUp
    SharedMemDown
    SharedMemLeft
    SharedMemRight
    SharedMemSelect
    SharedMemCancel
    Custom Plugin #1
    Custom Plugin #2
    Custom Plugin #3
    Custom Plugin #4
    Custom Plugin #5
    Custom Plugin #6
    Custom Plugin #7
    Custom Plugin #8
    Custom Plugin #9
    Custom Plugin #10
    Custom Plugin #11
    Custom Plugin #12
    CustomPlugin01
    CustomPlugin02
    CustomPlugin03
    CustomPlugin04
    CustomPlugin05
    CustomPlugin06
    CustomPlugin07
    CustomPlugin08
    CustomPlugin09
    CustomPlugin10
    CustomPlugin11
    CustomPlugin12
    ViewNextVehicle
    ViewPrevVehicle
    ViewMyVehicle
    CycleDriving
    CycleOnboard
    CycleSwingman
    CycleSpectator
    CycleTracking
    SwingmanPitchUp
    SwingmanPitchDown
    SwingmanYawLeft
    SwingmanYawRight
    SwingmanDecRadius
    SwingmanIncRadius
    SwingmanReset
    Camera_CamEd_Slow
    Camera_MoveForward
    Camera_MoveBackward
    Camera_MoveLeft
    Camera_MoveRight
    Camera_MoveUp
    Camera_MoveDown
    Camera_PitchUp
    Camera_PitchDown
    Camera_RollLeft
    Camera_RollRight
    Camera_YawLeft
    Camera_YawRight
    Camera_ZoomIn
    Camera_ZoomOut
    Toggle_HWPlugin
    VoiceChat_PTT
    CameraChange
    ResetFFB
    ToggleMFDA
    ToggleMFDB
    ToggleMFDC
    ToggleMFDD
    ToggleMFDE
    ToggleMFDF
    ToggleMFDG
    ToggleMFDH
    MessageHistory
    
    
     
  3. Uff

    Uff Registered

    Joined:
    Oct 5, 2010
    Messages:
    279
    Likes Received:
    51
    Yes, that's what I tried: I checked if (control, "Pause") == 0 and in that case I set fRetVal to 1.0. At the moment I didn't get it to work. :(
     
  4. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    7,407
    Likes Received:
    3,095
    Did you check that your test is being run and is being found true? Just asking because I chased my tail for hours once before working out the function still had a float as input, so wasn't being called...

    I haven't tried Pausing myself, so can't say for sure that it works.

    PS You didn't explicitly mention returning true from CheckHWControl(), you probably did... ?
     
  5. Uff

    Uff Registered

    Joined:
    Oct 5, 2010
    Messages:
    279
    Likes Received:
    51
    Yes, this time I did. :) I'll double check the return value, just to be sure it is really returning 1.0.
     
  6. Uff

    Uff Registered

    Joined:
    Oct 5, 2010
    Messages:
    279
    Likes Received:
    51
    I think I found the error: using the function reported on MSDN did not work, I used the one I linked in the OP and now the game pauses. So:

    keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);

    did not work. I had to remove "KEYEVENTF_EXTENDEDKEY |" and write the right keycode: I will try to experiment if I can now simulate Esc too. Thanks for your help Lazza. :)
     
  7. Uff

    Uff Registered

    Joined:
    Oct 5, 2010
    Messages:
    279
    Likes Received:
    51
    After doing further tests I managed to emulate an Esc keystroke, but I have some doubts on how CheckHWControl works. At first I thought that it would check if a button was pressed and, in that case, it would let you do some maths: let's say something like this.

    Code:
    if (_stricmp(controlName, "AlternateEsc") == 0)
      {
    	  WriteToAllExampleOutputFiles("a", "---PAUSE---");
              fRetVal = 1.0;
    	  return(true);
      }
    return (false);
    
    By doing this, though, as soon as the race starts I see the Esc menu appear without having to physically press it on my keyboard. With the following code, instead, when sessionStop == true the Esc menu appears, otherwise it doesn't.

    Code:
    if (_stricmp(controlName, "AlternateEsc") == 0)
      {
    	  if (sessionStop == true) {
    		  fRetVal = 1.0;
    		  sessionStop = false;
    	  }
    	  else {
    		  fRetVal = 0.0;
    	  }
    
    	  return(true);
      }
    
      return( false );
    
    So, my question is: is CheckHWControl a way to tell the game "Press this button for me when this condition is satisfied" instead of "The user pressed this button on the keyboard, now do your maths"?
     
  8. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    7,407
    Likes Received:
    3,095
    Every single graphics update, every single defined control is checked for. So CheckHWControl is called with controlName="Throttle", then again with controlName="Brake", ... all the way through every single control name. If the user has pressed any of those then rRetVal will show 1.0 (for digital) and presumably 0.0-1.0 for analog (not sure on that).

    So if you just test for controlName == "AlternateEsc", you'll get true every single frame (and because your first example then sets fRetVal to 1.0 and returns true, your game registers the Esc).

    To answer your question: both :)


    (your second example, you don't really need to set fRetVal to 0.0 if you don't want to Esc; it'll only be 1.0 if the user has pressed AltEsc, and you probably don't want to cancel it. You also probably only need to return true when you set it to 1.0)
     
  9. Uff

    Uff Registered

    Joined:
    Oct 5, 2010
    Messages:
    279
    Likes Received:
    51
    Thanks: it's more clear now. :)
     

Share This Page