ZeroAccend

Allow Paste in Payday 2 - Written in AHK

Mar 1st, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Payday 2 Paste Script
  2. ;Written by 0xB0BAFE77 (Greg G.)
  3. ;Made 2016-02-29
  4.  
  5. ;============================== Start Auto-Execution Section ==============================
  6.  
  7. ; Keeps script permanently running
  8. #Persistent
  9.  
  10. ; Avoids checking empty variables to see if they are environment variables.
  11. ; Recommended for performance and compatibility with future AutoHotkey releases.
  12. #NoEnv
  13.  
  14. ; Ensures that there is only a single instance of this script running.
  15. #SingleInstance, Force
  16.  
  17. ; Makes a script unconditionally use its own folder as its working directory.
  18. ; Ensures a consistent starting directory.
  19. SetWorkingDir %A_ScriptDir%
  20.  
  21. ; sets title matching to search for "containing" isntead of "exact"
  22. SetTitleMatchMode, 2
  23.  
  24. ; sets the key send input type. Event is used to make use of KeyDelay.
  25. SendMode, Event
  26.  
  27. ; Sets delay between key strokes and how long a key should be pressed.
  28. ; SetKeyDelay KeyStrokeDelay,
  29. SetKeyDelay 15, 10
  30.  
  31. return
  32.  
  33. ;============================== Payday 2 ==============================
  34. #IfWinActive, ahk_exe payday2_win32_release.exe
  35.  
  36. ;Custom paste function for Payday 2 since pasting isn't recognized natively.
  37. ;Ctrl+V pastes text into payday chat box.
  38. ^v::
  39.     ;Backup whatever is on the clipboard to var
  40.     clipSave    := ClipboardAll
  41.     ;Call paste function
  42.     paydayPaste(Clipboard)
  43.     ;Returns original content to clipboard.
  44.     Clipboard   := clipSave
  45.     ;Clears clipSave variable.
  46.     clipSave    := ""
  47.     return
  48.  
  49.  
  50. ;Paste function. cb = clipboard
  51. paydayPaste(cb)
  52. {
  53.     ;Replaces carriage returns/line feeds with {Enter} tag
  54.     ;This ensures a line break.
  55.     StringReplace, cb, cb, `r`n, %A_Space%{Enter}%A_Space%, all
  56.    
  57.     ;Removes formatting
  58.     cb := cb
  59.  
  60.     ;Payday 2's chat box can only accept a maximum of 78 characters
  61.     charLeft    := 78
  62.  
  63.     Loop, parse, cb, %A_Space%
  64.     {
  65.         ;Msgbox, A_Index is %A_Index% and A_LoopField is %A_LoopField%
  66.         ;Gets the length of the substring plus 1 for the space added later.
  67.         subStrLength := StrLen(A_LoopField) + 1
  68.        
  69.         ;Checks to make sure the substring isn't longer than the
  70.         ;the characters left in the input box.
  71.         if (subStrLength < charLeft)
  72.         {
  73.             if (A_LoopField = "{Enter}")
  74.             {
  75.                 Send, {Enter}
  76.                 charLeft := 78
  77.                 continue
  78.             }
  79.             ;Send next field along with a space at the end.
  80.             SendInput, %A_LoopField%{Space}
  81.             Sleep, 25
  82.             ;Update remaining characters
  83.             charLeft -= subStrLength
  84.         }
  85.         else
  86.         {
  87.             SendInput, %A_LoopField%{Space}
  88.             Sleep, 75
  89.             Send, {Enter}
  90.             charLeft    := 78
  91.             result      := ""
  92.         }
  93.     }
  94.     SendInput, %A_LoopField%{Space}
  95.     Sleep, 75
  96.     Send, {Enter}
  97.     charLeft    := 78
  98.     result      := ""
  99. }
  100. return
  101.  
  102. #IfWinActive
  103.  
  104. ;============================== End Script ==============================
Advertisement
Add Comment
Please, Sign In to add comment