Alan Martin
Joined: 10 Jul 2005 Posts: 2 Location: Australia
|
Posted: Sat Jul 16, 2005 7:27 am Post subject: hex <--> decimal conversion hotkeys |
|
|
I love how AHK can program every one of the Internet/Multimedia keys on my Logitech keyboard,
even when the iTouch driver software is not loaded (using Windows default driver).
I have made a couple of the extra keys do hex/decimal conversions with any size of number,
not just two digits as described here.
If I select a decimal number like 127 in any editor
and press the "Webcam" key (which I have labelled "hex")
it replaces that decimal number with: 0x7f
or if I press Alt+Webcam it converts it to: 7f
or if I press Ctrl+Webcam,
it replaces that decimal number with: 0x7f(127)
which is useful in documentation and notes.
If I select a hex number like 0x7f [or 7f without the leading 0x]
and press the "Messenger/SMS" key (which I have labelled "Dec")
it replaces that hex number with: 127
If I press Ctrl+"Messenger/SMS" instead,
it replaces that hex number with: 0x7f(127)
If I press any of those keys when the selection is not the
correct type of input, it just beeps and makes no change
-- for example trying to convert 0x7f or 7f to hex,
or trying to convert 123.45 or 0x7g or "bananas" to either
hex or decimal.
| Code: | ;; Necessary to prevent the default keyboard action:
#InstallKeybdHook
;; Ctrl+MessSMS key: 0xHH to 0xHH(decimal)
^sc111::
ClipSaved := ClipboardAll
Send, ^c
ClipWait, 1, 1
numin := Clipboard
if numin is not integer
{
Clipboard := ClipSaved
ClipSaved =
Soundbeep
Return
}
numin += 0
clipboard := numin
Send, {RIGHT}+9^v+0
Clipboard := ClipSaved
ClipSaved =
Return
;; MessSMS key: 0xHH to decimal
sc111::
ClipSaved := ClipboardAll
Send, ^c
ClipWait, 1, 1
numin := Clipboard
if numin is not integer
{
if numin is not xdigit
{
Clipboard := ClipSaved
ClipSaved =
Soundbeep
Return
}
else
numin = 0x%numin%
}
numin += 0
clipboard := numin
Send, ^v
Clipboard := ClipSaved
ClipSaved =
Return
;; Ctrl+Webcam key: decimal to 0xHH(decimal)
^sc112::
ClipSaved := ClipboardAll
Send, ^c
ClipWait, 1, 1
numin := Clipboard
if numin is not digit
{
Clipboard := ClipSaved
ClipSaved =
Soundbeep
Return
}
StringLen, LengthNumin, numin
SetFormat, integer, hex
numin += 0
SetFormat, integer, d
clipboard := numin
Send, {LEFT}^v+9{RIGHT %LengthNumin%}+0
Clipboard := ClipSaved
ClipSaved =
Return
;; Alt + Webcam key: decimal to HH
!sc112::
ClipSaved := ClipboardAll
Send, ^c
ClipWait, 1, 1
numin := Clipboard
if numin is not digit
{
Clipboard := ClipSaved
ClipSaved =
Soundbeep
Return
}
SetFormat, integer, hex
numin += 0
SetFormat, integer, d
StringTrimLeft, newnumin, numin, 2
clipboard := newnumin
Send, ^v
Clipboard := ClipSaved
ClipSaved =
Return
;; Webcam key: decimal to 0xHH
sc112::
ClipSaved := ClipboardAll
Send, ^c
ClipWait, 1, 1
numin := Clipboard
if numin is not digit
{
Clipboard := ClipSaved
ClipSaved =
Soundbeep
Return
}
SetFormat, integer, hex
numin += 0
SetFormat, integer, d
clipboard := numin
Send, ^v
Clipboard := ClipSaved
ClipSaved =
Return |
|
|