Skip to content

Commit

Permalink
Item highlighting improvements/fixes (PoE-TradeMacro#88)
Browse files Browse the repository at this point in the history
* WIP, use clipboard pasting for item highlighting as a better dead key workaround

* removed obsolete deadKeyWorkaround

* fixed some item highlighting issue
  • Loading branch information
Eruyome authored and aRTy42 committed May 13, 2017
1 parent 9500396 commit 310525a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 52 deletions.
87 changes: 38 additions & 49 deletions resources/ahk/POE-ItemInfo.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -9631,23 +9631,34 @@ CloseScripts() {
ExitApp
}

HighlightItems(broadTerms = false, leaveSearchField = true, deadKeysWorkaround = false) {
HighlightItems(broadTerms = false, leaveSearchField = true) {
; Highlights items via stash search (also in vendor search)
IfWinActive, Path of Exile ahk_class POEWindowClass
{
Global Item, Opts, Globals, ItemData

ClipBoardTemp := Clipboard
SuspendPOEItemScript = 1 ; This allows us to handle the clipboard change event
Send ^{sc02E} ; ^{c}
Sleep 100

CBContents := GetClipboardContents()
CBContents := PreProcessContents(CBContents)

Globals.Set("ItemText", CBContents)
Globals.Set("TierRelativeToItemLevelOverride", Opts.TierRelativeToItemLevel)

ParsedData := ParseItemData(CBContents)
; Parse the clipboard contents twice.
; If the clipboard contains valid item data before we send ctrl + c to try and parse an item via ctrl + f then don't restore that clipboard data later on.
; This prevents the highlighting funtion to fill search fields with data from previous item parsings/manual data copying since
; that clipboard data would always be restored again.
Loop, 2 {
If (A_Index = 2) {
Clipboard :=
Send ^{sc02E} ; ^{c}
Sleep 100
}
CBContents := GetClipboardContents()
CBContents := PreProcessContents(CBContents)
Globals.Set("ItemText", CBContents)
Globals.Set("TierRelativeToItemLevelOverride", Opts.TierRelativeToItemLevel)
ParsedData := ParseItemData(CBContents)
If (A_Index = 1 and Item.Name) {
dontRestoreClipboard := true
}
}

If (Item.Name) {
rarity := ""
Expand Down Expand Up @@ -9799,59 +9810,37 @@ HighlightItems(broadTerms = false, leaveSearchField = true, deadKeysWorkaround =
If (terms.length() > 0) {
SendInput ^{sc021} ; sc021 = f
searchText =
For key, val in terms {
; some keyboard layouts translate special characters like ^ ' " ` ~ combined with e/i/u/o/a into a special character, for example Dutch: ë (dead keys)
; solution: add a space after every one of those characters
If (deadKeysWorkaround) {
If (RegExMatch(val, "i)^[eioau]")) {
; space after opening quotation mark only needed for vowels
searchText = %searchText% " %val%"
} Else {
searchText = %searchText% "%val%"
}

If (key == terms.Length()) {
; the last space won't be added/typed so we add a tailing character and remove it again
; this should result in the string ending with "{Space}
space := " s"
searchText = %searchText% %space%
StringTrimRight, searchText, searchText, 2
}
} Else {
searchText = %searchText% "%val%"
}
For key, val in terms {
searchText = %searchText% "%val%"
}

; the search field has a 50 character limit, we have to close the last term with a quotation mark
If (StrLen(searchText) > 50) {
newString := SubStr(searchText, 1, 50)
temp := RegExReplace(newString, "i)""", Replacement = "", QuotationMarks)
; make sure we have an equal amount of quotation marks (all terms properly enclosed)
If (QuotationMarks&1) {
If (deadKeysWorkaround) {
searchText := RegExReplace(newString, "i).{2}$", """ ")
} Else {
searchText := RegExReplace(newString, "i).$", """")
}
If (QuotationMarks&1) {
searchText := RegExReplace(newString, "i).$", """")
}
}

SendInput %searchText%

Clipboard := searchText
Sleep 10
SendEvent ^{sc02f} ; ctrl + v
If (leaveSearchField) {
SendInput {Enter}
} Else {
SendInput ^{A}
SendInput {sc01c} ; enter
} Else {
SendInput ^{sc01e} ; ctrl + a
}
} Else {
; send ctrl + f in case we don't have information to input
SendInput ^{sc021}
} Else {
SendInput ^{sc021} ; send ctrl + f in case we don't have information to input
}

SuspendPOEItemScript = 0 ; Allow Item info to handle clipboard change event
If (Item.Name) {
; revert the initial clipboard upon succeeding to parse any item (doesn't cause clipboard change events otherwise)
Sleep, 10
If (!dontRestoreClipboard) {
Clipboard := ClipBoardTemp
}
}
SuspendPOEItemScript = 0 ; Allow Item info to handle clipboard change event
}
}

Expand Down
5 changes: 2 additions & 3 deletions resources/ahk/default_AdditionalMacros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
Pause::TogglePOEItemScript() ; Pause item parsing with the pause key (other macros remain).
#D::WinMinimize, A ; Winkey+D minimizes the active PoE window (PoE stays minimized this way).

^F::HighlightItems(false,true,false) ; Ctrl+F fills search bars in the stash or vendor screens with the item's name or info you're hovering over.
^F::HighlightItems(false,true) ; Ctrl+F fills search bars in the stash or vendor screens with the item's name or info you're hovering over.
; Function parameters, change if needed or wanted:
; 1. Use broader terms, default = false.
; 2. Leave the search field after pasting the search terms, default = true.
; 3. Workaround for keyboard layouts with "dead keys", default = false. (Some Layouts need this to prevent adding special characters when using a quotation mark).
^!F::HighlightItems(true,true,false) ; Ctrl+Alt+F uses much broader search terms for the highlight function.
^!F::HighlightItems(true,true) ; Ctrl+Alt+F uses much broader search terms for the highlight function.

; ^Escape::CloseScripts() ; Ctrl+Esc closes all running scripts specified by (and including) ItemInfo or TradeMacro.

Expand Down

0 comments on commit 310525a

Please sign in to comment.