Autohotkey PixelGetColor在自动热键中不工作的RGB值
带有PixelGetColor命令的RGB(十进制)值在自动热键中不起作用。 如果您使用命令行,Autohotkey PixelGetColor在自动热键中不工作的RGB值,autohotkey,Autohotkey,带有PixelGetColor命令的RGB(十进制)值在自动热键中不起作用。 如果您使用命令行,PixelGetColor,color,%MouseX%,%MouseY%,RGB 它会给我一个[RGB(十进制)值],但它会给我一个[RGB(十六进制)] 默认情况下,如果使用命令行:PixelGetColor,color,%MouseX%,%MouseY% 然后它会给我一个[RGB(十六进制)值],但它会给我一个[BGR(十六进制)值] 注意-我确实根据评论重新编辑了我的问题 我听说是BGR格式的
PixelGetColor,color,%MouseX%,%MouseY%,RGB
它会给我一个[RGB(十进制)值],但它会给我一个[RGB(十六进制)]
默认情况下,如果使用命令行:PixelGetColor,color,%MouseX%,%MouseY%
然后它会给我一个[RGB(十六进制)值],但它会给我一个[BGR(十六进制)值]
注意-我确实根据评论重新编辑了我的问题
我听说是BGR格式的,我不明白我们为什么要这样
我想用户和我都希望得到更多这样的结果[默认值:RGB>十六进制值]和参数[,RGB>十进制值]
现在的问题是,如何从PixelGetColor命令获取RGB(十进制)值
此AHK脚本不起作用
颜色选择器
;#notrayicon
#SingleInstance force
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
MouseGetPos MouseX, MouseY
;PixelGetColor, color, %MouseX%, %MouseY% ;The default result is a BGR>Hex Value - i wish this should be RGB>Hex
PixelGetColor, color, %MouseX%, %MouseY%, RGB ;RGB Parameter i wish it should be have a RGB>Decimal value - otherwise this parameter does not have for me a useful function.
MsgBox,, , The color at the current cursor position is %color%., 3
return
;#notrayicon
#SingleInstance force
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
MouseGetPos MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%, RGB
a := HexToRgb(color)
MsgBox,, , The color at the current cursor position is %a%, 0
;MsgBox, % "Example:`n`n" . rgbToHex("255,255,255") . "`n" . HexToRgb("0xFFFFFF") . "`n" . CheckHexC("000000")
return
rgbToHex(s, d = "") {
StringSplit, s, s, % d = "" ? "," : d
SetFormat, Integer, % (f := A_FormatInteger) = "D" ? "H" : f
h := s1 + 0 . s2 + 0 . s3 + 0
SetFormat, Integer, %f%
Return, "#" . RegExReplace(RegExReplace(h, "0x(.)(?=$|0x)", "0$1"), "0x")
}
hexToRgb(s, d = "") {
SetFormat, Integer, % (f := A_FormatInteger) = "H" ? "D" : f
Loop, % StrLen(s := RegExReplace(s, "^(?:0x|#)")) // 2
c%A_Index% := 0 + (h := "0x" . SubStr(s, A_Index * 2 - 1, 2))
SetFormat, Integer, %f%
Return, c1 . (d := d = "" ? "," : d) . c2 . d . c3
}
CheckHexC(s, d = "") {
If InStr(s, (d := d = "" ? "," : d))
e := hexToRgb(rgbToHex(s, d), d) = s
Else e := rgbToHex(hexToRgb(s)) = (InStr(s, "#") ? "" : "#"
. RegExReplace(s, "^0x"))
Return, e
}
自动热键文档命令>
如果要获取[RGB值] 可以首先使用PixelGetColor命令 然后使用函数转换HexToRgb(颜色) 尝试以下AHK脚本: 颜色选择器
;#notrayicon
#SingleInstance force
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
MouseGetPos MouseX, MouseY
;PixelGetColor, color, %MouseX%, %MouseY% ;The default result is a BGR>Hex Value - i wish this should be RGB>Hex
PixelGetColor, color, %MouseX%, %MouseY%, RGB ;RGB Parameter i wish it should be have a RGB>Decimal value - otherwise this parameter does not have for me a useful function.
MsgBox,, , The color at the current cursor position is %color%., 3
return
;#notrayicon
#SingleInstance force
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
MouseGetPos MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%, RGB
a := HexToRgb(color)
MsgBox,, , The color at the current cursor position is %a%, 0
;MsgBox, % "Example:`n`n" . rgbToHex("255,255,255") . "`n" . HexToRgb("0xFFFFFF") . "`n" . CheckHexC("000000")
return
rgbToHex(s, d = "") {
StringSplit, s, s, % d = "" ? "," : d
SetFormat, Integer, % (f := A_FormatInteger) = "D" ? "H" : f
h := s1 + 0 . s2 + 0 . s3 + 0
SetFormat, Integer, %f%
Return, "#" . RegExReplace(RegExReplace(h, "0x(.)(?=$|0x)", "0$1"), "0x")
}
hexToRgb(s, d = "") {
SetFormat, Integer, % (f := A_FormatInteger) = "H" ? "D" : f
Loop, % StrLen(s := RegExReplace(s, "^(?:0x|#)")) // 2
c%A_Index% := 0 + (h := "0x" . SubStr(s, A_Index * 2 - 1, 2))
SetFormat, Integer, %f%
Return, c1 . (d := d = "" ? "," : d) . c2 . d . c3
}
CheckHexC(s, d = "") {
If InStr(s, (d := d = "" ? "," : d))
e := hexToRgb(rgbToHex(s, d), d) = s
Else e := rgbToHex(hexToRgb(s)) = (InStr(s, "#") ? "" : "#"
. RegExReplace(s, "^0x"))
Return, e
}
如果要获取[RGB值] 可以首先使用PixelGetColor命令 然后使用函数转换HexToRgb(颜色) 尝试以下AHK脚本: 颜色选择器
;#notrayicon
#SingleInstance force
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
MouseGetPos MouseX, MouseY
;PixelGetColor, color, %MouseX%, %MouseY% ;The default result is a BGR>Hex Value - i wish this should be RGB>Hex
PixelGetColor, color, %MouseX%, %MouseY%, RGB ;RGB Parameter i wish it should be have a RGB>Decimal value - otherwise this parameter does not have for me a useful function.
MsgBox,, , The color at the current cursor position is %color%., 3
return
;#notrayicon
#SingleInstance force
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
MouseGetPos MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%, RGB
a := HexToRgb(color)
MsgBox,, , The color at the current cursor position is %a%, 0
;MsgBox, % "Example:`n`n" . rgbToHex("255,255,255") . "`n" . HexToRgb("0xFFFFFF") . "`n" . CheckHexC("000000")
return
rgbToHex(s, d = "") {
StringSplit, s, s, % d = "" ? "," : d
SetFormat, Integer, % (f := A_FormatInteger) = "D" ? "H" : f
h := s1 + 0 . s2 + 0 . s3 + 0
SetFormat, Integer, %f%
Return, "#" . RegExReplace(RegExReplace(h, "0x(.)(?=$|0x)", "0$1"), "0x")
}
hexToRgb(s, d = "") {
SetFormat, Integer, % (f := A_FormatInteger) = "H" ? "D" : f
Loop, % StrLen(s := RegExReplace(s, "^(?:0x|#)")) // 2
c%A_Index% := 0 + (h := "0x" . SubStr(s, A_Index * 2 - 1, 2))
SetFormat, Integer, %f%
Return, c1 . (d := d = "" ? "," : d) . c2 . d . c3
}
CheckHexC(s, d = "") {
If InStr(s, (d := d = "" ? "," : d))
e := hexToRgb(rgbToHex(s, d), d) = s
Else e := rgbToHex(hexToRgb(s)) = (InStr(s, "#") ? "" : "#"
. RegExReplace(s, "^0x"))
Return, e
}
虽然另一个答案可行而且确实很聪明,但它有点冗长和复杂。
Format
函数是内置的,可以转换十六进制。至十二月
因此,使用您的代码并添加一行进行格式化,我们可以通过以下方法解决此问题:
f1::
MouseGetPos MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%, RGB
color := Format( "{1:u},{1:u},{1:u}", "0x" . SubStr(color, 3, 2), "0x" . SubStr(color, 5, 2), "0x" . SubStr(color, 7, 2))
MsgBox,, , The color at the current cursor position is %color%., 3
return
我敢打赌,有一种更有效的方法,但目前我无法理解。虽然另一个答案可行,而且确实很聪明,但它有点冗长和复杂。
Format
函数是内置的,可以转换十六进制。至十二月
因此,使用您的代码并添加一行进行格式化,我们可以通过以下方法解决此问题:
f1::
MouseGetPos MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%, RGB
color := Format( "{1:u},{1:u},{1:u}", "0x" . SubStr(color, 3, 2), "0x" . SubStr(color, 5, 2), "0x" . SubStr(color, 7, 2))
MsgBox,, , The color at the current cursor position is %color%., 3
return
我敢打赌,有一种更有效的方法,但目前我无法理解。您误解了RGB选项的作用。请注意,“RGB值”通常可视为十六进制。或者12月,你的问题暗示它不是隐含的十进制。碰巧AHK将RGB值检索为十六进制。因此,它确实工作正常。我建议进行一次编辑,澄清您需要十进制值,但您拒绝了。。。。无论如何,我建议澄清您的问题,以反映您实际提出的问题-这是从十六进制RGB值到十进制RGB值的转换。@Evan Elrod-您是对的,“RGB值”可以是(十六进制值)或(十进制值)-我拒绝您编辑的原因是-参数,RGB必须有一个函数-十六进制的默认命令代码是
PixelGetColor,color,%MouseX%,%MouseY%
,十进制的默认命令代码应该是PixelGetColor,color,%MouseX%,%MouseY%,RGB
-我希望您理解我为什么这么做-但无论如何,我要感谢您提供的信息。PixelGetColor
命令的RGB
选项没有给出小数。它指定了顺序。默认情况下,会将其列为BGR,并将红色和蓝色交换。从你发布的链接中,“RGB:检索RGB与BGR格式的颜色。换句话说,红色和蓝色的分量被交换。”@Evan Elrod-我听说BGR格式的颜色很奇怪,但你是对的,默认值是BGR,红色和蓝色被交换。我不明白他们为什么要这样做-我想用户和我都希望更像这样[Default=RGB>HEX Value],并使用参数[,RGB=RGB>Decimal Value]-但是感谢这些信息,我将重新编辑我的问题。我同意将Decimal Value作为替代输出会很有用。我也不需要BGR。你误解了RGB选项的作用。请注意,“RGB值”通常可视为十六进制。或者12月,你的问题暗示它不是隐含的十进制。碰巧AHK将RGB值检索为十六进制。因此,它确实工作正常。我建议进行一次编辑,澄清您需要十进制值,但您拒绝了。。。。无论如何,我建议澄清您的问题,以反映您实际提出的问题-这是从十六进制RGB值到十进制RGB值的转换。@Evan Elrod-您是对的,“RGB值”可以是(十六进制值)或(十进制值)-我拒绝您编辑的原因是-参数,RGB必须有一个函数-十六进制的默认命令代码是PixelGetColor,color,%MouseX%,%MouseY%
,十进制的默认命令代码应该是PixelGetColor,color,%MouseX%,%MouseY%,RGB
-我希望您理解我为什么这么做-但无论如何,我要感谢您提供的信息。PixelGetColor
命令的RGB
选项没有给出小数。它指定了顺序。默认情况下,会将其列为BGR,并将红色和蓝色交换。从你发布的链接中,“RGB:检索RGB与BGR格式的颜色。换句话说,红色和蓝色的分量被交换。”@Evan Elrod-我听说BGR格式的颜色很奇怪,但你是对的,默认值是BGR,红色和蓝色被交换。我不明白他们为什么要这样做-我想用户和我都希望更像这样[Default=RGB>HEX Value],并使用参数[,RGB=RGB>Decimal Value]-但是感谢这些信息,我将重新编辑我的问题。我同意将Decimal Value作为替代输出会很有用。我也不需要BGR。这是因为SetFormat
不推荐使用。这是因为SetFormat
不推荐使用。