Emoji() : 40 unicode icons

Post your working scripts, libraries and tools
User avatar
SKAN
Posts: 820
Joined: 29 Sep 2013, 16:58

Emoji() : 40 unicode icons

08 Sep 2020, 14:29

Preview of defined icons:

😊 smile      😄 happy     😁 laugh     😍 surprise  😂 lol
😜 razz       😎 cool      😉 wink      😴 zzz       😐 neutral
😶 silent     😒 eh        😞 sad       😢 cry       😭 col
😳 oops       😵 confused  😰 anxious   😲 shock     😱 omg
😤 vent       😠 mad       😡 angry     👿 evil      😈 twisted
💯 100        👏 clap      💖 heart     👀 eyes      💩 poop
🙏 thanks     👍 thumbup   👌 super     🎯 bullseye  👎 thumbdown
🎅 santa      😇 angel     💀 skull     👻 ghost     👽 alien

 
Usage:
 
  Image
 
Save and run the script with AutoHotkey 1.1 (Unicode).
When in an input capable window, type hotstring ??? to trigger Emoji() which will display an UI.
Type a key phrase, for eg. smile or :). Note: :arrow: You may also type in the uni-code 0x1F60A or 1F60A or 128522
Press Enter to confirm or Esc to cancel.
Emoticon would be pasted at the caret position of active window.
 

Note: Only limited testing was done.
You will see box character in MS Word. Select char and set font to "Segoe UI Symbol" (may be 36pt)
Works fine in text editors like notepad, metapad, PSPad, wordpad.
Works fine when composing mail in browsers.
Works fine in Facebook posts.
Works fine with AutoHotkey posts. (See preview above)
 

The script:
 

Code: Select all

#NoEnv ;                                           Emoji script v0.21 by SKAN on D397/D39A
#Warn                            ; https://www.autohotkey.com/boards/viewtopic.php?t=80793
#SingleInstance, Force ; emoji list: https://unicode.org/emoji/charts/full-emoji-list.html
SetBatchLines, -1

Hotstring(":*X:???", "Emoji")
Return                                                        ; end of autoexecute section
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Emoji() {
Local
  If !( Input := Emoji_InputHook(ID:=WinExist("A")) )
    Return
  Body := Format("<span style=""font-size:48px"">&#{:d};</span>", Input)
  SetClipboardHTML(Body,, Chr(Input))
  If WinActive("ahk_id" . ID)
     SendInput ^v
Return
}
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Emoji_InputHook(hWnd) {
Local
Static hBM:=0

  If !(hBM)
  {
    VarSetCapacity(BMBITS, 180*4, 240)
    hBM:=DllCall("CreateBitmap", "Int",180,"Int",1,"Int",1, "Int",32,"Ptr",&BMBITS, "Ptr")
  }

  hMon := DllCall("MonitorFromWindow", "Ptr",hWnd, "Int",0x2, "Ptr")   ; _DEFAULTTONEAREST
  VarSetCapacity(MONITORINFO,40,0), NumPut(40, MONITORINFO,"Int")
  DllCall("GetMonitorInfo", "Ptr",hMon, "Ptr",&MONITORINFO)
  MX:=NumGet(MONITORINFO, 4, "Int"), MW:=NumGet(MONITORINFO, 12, "Int")-MX
  MY:=NumGet(MONITORINFO, 8, "Int"), MH:=NumGet(MONITORINFO, 16, "Int")-MY

  DetectHiddenWindows, % ("On", DHW:=A_DetectHiddenWindows)
  SetWinDelay, % (0, SWD := A_WinDelay)
  SetControlDelay, % (0. SCD := A_ControlDelay)
  SplashImage, 10:HBITMAP:* %hBM%, ZY4 ZX12 ZH1 FM36 FS18 C11 CTF0F0F0 CW00AAAA B1 Hide
                               , % Chr(32),% Chr(191), Emoji, Segoe UI
  WinWait, Emoji ahk_class AutoHotkey2
  WinGetPos,,,WW, WH
  WinMove,,, % MX+( (MW//2)-(WW//2) ), % MY+( (MH//2)-(WH//2) )
  SplashImage, 10:Show
  ControlSetText, Static2, % Input:=(Key:=(PreviousKey:=""))

  ih := InputHook("M","{Escape}{Enter}{NumpadEnter}{``}")
  ih.KeyOpt("{All}", "S")
  ih.KeyOpt("{Space}{Tab}", "I")
  ih.KeyOpt("{RShift}{LShift}", "-S")
  ih.Start()

  While (ih.InProgress && A_TimeIdle<180000)
  {
    Sleep 1
    If ((Key:=ih.Input)=PreviousKey)
      Continue
    ControlSetText, Static2, % ( PreviousKey:=Key )
    ControlSetText, Static1, % ( Key="" ? Chr(191) : Chr(Input:=Emoji_Code(Key)))
  }

  SplashImage, 10:OFF
  SetControlDelay, %SCD%
  SetWinDelay, %SWD%
  DetectHiddenWindows, %DHW%

Return (ih.InProgress ? Round(ih.Stop()) : ih.EndKey="Escape" ? 0 : Input)
}
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Emoji_Code(Key) {

  Switch (Key)
  {
     Case ":-)", ":)", ":-]", ":]", "=]", "=)", "smile"     : Return 0x1F60A ;       smile
     Case ":‑D", ":D", "x‑D", "xD", "=D", "happy"           : Return 0x1F604 ;       happy
     Case "laugh"                                           : Return 0x1F601 ;       laugh
     Case ":0", ":-0", "surpr", "surprise"                  : Return 0x1F60D ;    surprise
     Case "lol", "laughing"                                 : Return 0x1F602 ;         lol

     Case ":p", ":-p", ":b", ":-b", "=p", "razz"            : Return 0x1F61C ;        razz
     Case "8)", "8-)", "cool"                               : Return 0x1F60E ;        cool
     Case ";‑)", ";)", "wink"                               : Return 0x1F609 ;        wink
     Case "zzz", "sleep"                                    : Return 0x1F634 ;         zzz
     Case ":|", ":-|", "neut", "neutral"                    : Return 0x1F610 ;     neutral

     Case ";", ";-", ":", ":-", "silent"                    : Return 0x1F636 ;      silent
     Case "eh"                                              : Return 0x1F612 ;          eh
     Case ":‑(", ":(", ":‑[", ":[", "sad"                   : Return 0x1F61E ;         sad
     Case ":'‑(", ":'(", "cry"                              : Return 0x1F622 ;         cry
     Case ":'‑(", ":'(", "col", "crying"                    : Return 0x1F62D ;      crying

     Case "oops", "embar", "embarassed"                     : Return 0x1F633 ;        oops
     Case "%)", "roll", "confused"                          : Return 0x1F635 ;    confused
     Case "anx", "anxious"                                  : Return 0x1F630 ;     anxious
     Case ":O", ":-O", "shock"                              : Return 0x1F632 ;       shock
     Case "omg", "ohno"                                     : Return 0x1F631 ;         omg

     Case "vent"                                            : Return 0x1F624 ;        vent
     Case ":x", "mad"                                       : Return 0x1F620 ;         mad
     Case "angry"                                           : Return 0x1F621 ;       angry
     Case ">:-(", "evil"                                    : Return 0x1F47F ;        evil
     Case ">:-)", "twisted"                                 : Return 0x1F608 ;     twisted

     Case "100"                                             : Return 0x1F4AF ;         100
     Case "clap"                                            : Return 0x1F44F ;        clap
     Case "<3", "heart"                                     : Return 0x1F496 ;       heart
     Case "eyes"                                            : Return 0x1F440 ;        eyes
     Case "poop"                                            : Return 0x1F4A9 ;        poop

     Case "thx", "thanx", "thanks"                          : Return 0x1F64F ;      thanks
     Case "thumbup", "+1"                                   : Return 0x1F44D ;     thumbup
     Case "super"                                           : Return 0x1F44C ;       super
     Case "bullseye", "bulls"                               : Return 0x1F3AF ;    bullseye
     Case "thumbdown", "-1"                                 : Return 0x1F44E ;   thumbdown

     Case "santa"                                           : Return 0x1F385 ;       santa
     Case "angel"                                           : Return 0x1F607 ;       angel
     Case "skull"                                           : Return 0x1F480 ;       skull
     Case "ghost"                                           : Return 0x1F47B ;       ghost
     Case "alien"                                           : Return 0x1F47D ;       alien
  }

  If Key is number
     Return Format("0x{:05x}", Round(Key))
  If Key is xdigit
     Return Format("0x{:05X}", Round("0x" . LTrim(Key,"0x"))+0)

Return 0
}
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SetClipboardHTML(HtmlBody, HtmlHead:="", AltText:="") {       ; v0.66 by SKAN on D393/D396
Local  F, Html, pMem, Bytes, hMemHTM:=0, hMemTXT:=0, Res1:=1, Res2:=1   ; @ tiny.cc/t80706
Static CF_UNICODETEXT:=13,   CFID:=DllCall("RegisterClipboardFormat", "Str","HTML Format")

  If ! DllCall("OpenClipboard", "Ptr",A_ScriptHwnd)
    Return 0
  Else DllCall("EmptyClipboard")

  If (HtmlBody!="")
  {
      Html     := "Version:0.9`r`nStartHTML:00000000`r`nEndHTML:00000000`r`nStartFragment"
               . ":00000000`r`nEndFragment:00000000`r`n<!DOCTYPE>`r`n<html>`r`n<head>`r`n"
                         . HtmlHead . "`r`n</head>`r`n<body>`r`n<!--StartFragment -->`r`n"
                              . HtmlBody . "`r`n<!--EndFragment -->`r`n</body>`r`n</html>"

      Bytes    := StrPut(Html, "utf-8")
      hMemHTM  := DllCall("GlobalAlloc", "Int",0x42, "Ptr",Bytes+4, "Ptr")
      pMem     := DllCall("GlobalLock", "Ptr",hMemHTM, "Ptr")
      StrPut(Html, pMem, Bytes, "utf-8")

      F := DllCall("Shlwapi.dll\StrStrA", "Ptr",pMem, "AStr","<html>", "Ptr") - pMem
      StrPut(Format("{:08}", F), pMem+23, 8, "utf-8")
      F := DllCall("Shlwapi.dll\StrStrA", "Ptr",pMem, "AStr","</html>", "Ptr") - pMem
      StrPut(Format("{:08}", F), pMem+41, 8, "utf-8")
      F := DllCall("Shlwapi.dll\StrStrA", "Ptr",pMem, "AStr","<!--StartFra", "Ptr") - pMem
      StrPut(Format("{:08}", F), pMem+65, 8, "utf-8")
      F := DllCall("Shlwapi.dll\StrStrA", "Ptr",pMem, "AStr","<!--EndFragm", "Ptr") - pMem
      StrPut(Format("{:08}", F), pMem+87, 8, "utf-8")

      DllCall("GlobalUnlock", "Ptr",hMemHTM)
      Res1  := DllCall("SetClipboardData", "Int",CFID, "Ptr",hMemHTM)
  }

  If (AltText!="")
  {
      Bytes    := StrPut(AltText, "utf-16")
      hMemTXT  := DllCall("GlobalAlloc", "Int",0x42, "Ptr",(Bytes*2)+8, "Ptr")
      pMem     := DllCall("GlobalLock", "Ptr",hMemTXT, "Ptr")
      StrPut(AltText, pMem, Bytes, "utf-16")
      DllCall("GlobalUnlock", "Ptr",hMemHTM)
      Res2  := DllCall("SetClipboardData", "Int",CF_UNICODETEXT, "Ptr",hMemTXT)
  }

  DllCall("CloseClipboard")

  hMemHTM := hMemHTM ? DllCall("GlobalFree", "Ptr",hMemHTM) : 0
  hMemTXT := hMemTXT ? DllCall("GlobalFree", "Ptr",hMemTXT) : 0

Return (Res1 & Res2)
}
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
Tigerlily
Posts: 353
Joined: 04 Oct 2018, 22:31

Re: Emoji() : Working script with 40 unicode icons

08 Sep 2020, 18:06

Super cool @SKAN

I was planning to make something like this a long time ago but got sidetracked on more important work projects :*D nice work
-TL
ozzii
Posts: 370
Joined: 30 Oct 2013, 06:04

Re: Emoji() : Working script with 40 unicode icons

09 Sep 2020, 03:55

really 😎
Some thoughts.....
Maybe just a tooltip for knowing that we type an emoji.
And maybe also a sort of help key for knowing what we can use for emoji
User avatar
SKAN
Posts: 820
Joined: 29 Sep 2013, 16:58

Re: Emoji() : Working script with 40 unicode icons

09 Sep 2020, 06:04

@Tigerlily Thanks for the feed back :) :thumbup:
 
ozzii wrote: really 😎
Thanks :)
ozzii wrote:Maybe just a tooltip for knowing that we type an emoji.
Show tooltip near where? Finding the caret position seems to be impossible in many situations.
I will have to show an UI center-screen with support for multi-monitor setup.
Thanks for the suggestion. I will implement an UI.

ozzii wrote: And maybe also a sort of help key for knowing what we can use for emoji
 
:idea:
Take a screenshot of my "preview" above, crop it as needed and save it.
Bind a Hotkey to SplashImage and see your saved image when needed.

Of course, I expect people to alter the key-phrases and may add/remove icons as needed.
In which case use the topic Test your Forum Posts to compose
your own preview and take a screen shot.

:)
User avatar
jNizM
Posts: 2663
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Emoji() : Working script with 40 unicode icons

09 Sep 2020, 06:15

Win + . ?

Image

But anyway... nice script like always
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
kczx3
Posts: 1170
Joined: 06 Oct 2015, 21:39

Re: Emoji() : Working script with 40 unicode icons

09 Sep 2020, 06:53

@jNizM agreed. Although that’s not available on all Win10 versions.
User avatar
SKAN
Posts: 820
Joined: 29 Sep 2013, 16:58

Re: Emoji() : Working script with 40 unicode icons

09 Sep 2020, 07:46

jNizM wrote:
09 Sep 2020, 06:15
Win + . ?
 
I didn't know.
Tried it on my other 2 (family) PC's which runs on Win10 2004 and yes, it is good. Thanks. :)

I don't use Win10. I recently upgraded to Win81 to make a few tests, like WinSet,Transparent on controls.
I will probably fallback to my special edition of Win7 which should receive updates for next couple of years, at least. :)

One more thing:
The Html paste has its advantages.. For example, in <span style=""font-size: 48px"">&#{:d};</span>
you may increase the font-size, for eg. 1024px which I'm not sure is possible with regular methods.

Edit: Mmm. The emoji is being sent as 48x48px in GMAIL :D
User avatar
SKAN
Posts: 820
Joined: 29 Sep 2013, 16:58

Re: Emoji() : Working script with 40 unicode icons

10 Sep 2020, 13:12

Hi @ozzii,

Code updated. An UI will be shown when hook is active.
Couldn't post a screenshot since InputHook wouldn't let me do a Alt+PrintScreen.
Please test and let me know.

:thumbup: :D

Edit: Managed to shoot screen.
 
emoji_ui.png
emoji_ui.png (2.48 KiB) Viewed 319 times
ozzii
Posts: 370
Joined: 30 Oct 2013, 06:04

Re: Emoji() : 40 unicode icons

11 Sep 2020, 05:50

Really nice.
And also love your GUI 👌
User avatar
SKAN
Posts: 820
Joined: 29 Sep 2013, 16:58

Re: Emoji() : 40 unicode icons

11 Sep 2020, 15:43

ozzii wrote:
11 Sep 2020, 05:50
Really nice.
And also love your GUI 👌
 
Thanks @ozzii :) :thumbup:
guest3456
Posts: 3145
Joined: 09 Oct 2013, 10:31

Re: Emoji() : Working script with 40 unicode icons

11 Sep 2020, 17:33

jNizM wrote:
09 Sep 2020, 06:15
Win + . ?
i think WIN + ; is the same also, that's what i use

Helgef
Posts: 4462
Joined: 17 Jul 2016, 01:02
Contact:

Re: Emoji() : 40 unicode icons

12 Sep 2020, 06:12

Nice, thanks for sharing :thumbsup: :heart:

Cheers.
neogna2
Posts: 74
Joined: 15 Sep 2016, 15:44

Re: Emoji() : 40 unicode icons

12 Sep 2020, 13:19

Nice script SKAN! Just FYI the Win10 bundled emoji picker is about to get a rework soon, see https://blogs.windows.com/windows-insider/2020/09/02/announcing-windows-10-insider-preview-build-20206/. But I like having your function as an alternative.

Code: Select all

Emoji script v0.21 by SKAN on D397/D39A
The D397/D39A part is a timestamp right? What format is that in? Your way of writing functions is very compact so I suppose it only consistent that you use a terse time format too :)
User avatar
SKAN
Posts: 820
Joined: 29 Sep 2013, 16:58

Re: Emoji() : 40 unicode icons

14 Sep 2020, 06:38

Helgef wrote: Nice, thanks for sharing :thumbsup: :heart:
 
:) :thumbup:
User avatar
SKAN
Posts: 820
Joined: 29 Sep 2013, 16:58

Re: Emoji() : 40 unicode icons

14 Sep 2020, 06:46

neogna2 wrote: Nice script SKAN!
 
Thank you :)
 
neogna2 wrote: Just FYI the Win10 bundled emoji picker is about to get a rework soon, see https://blogs.windows.com/windows-insider/2020/09/02/announcing-windows-10-insider-preview-build-20206/. But I like having your function as an alternative.
Thanks for the info and link.
 
neogna2 wrote:

Code: Select all

Emoji script v0.21 by SKAN on D397/D39A
The D397/D39A part is a timestamp right? What format is that in? Your way of writing functions is very compact so I suppose it only consistent that you use a terse time format too :)
 
:D
You seem to read me well.
Yes. They are Creation/Last Modified DateTime stamps of .ahk file, 50% compressed, using my unpatented ( :P ) method.
I guess, I should post the function pair. I will tag you in the topic to let you know.
Thanks again.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: bitelse and 20 guests