Characters tables (Alternative to the PB tool)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

Re: Characters tables (Alternative to the PB tool)

Post by boddhi »

@Caronte3D, Infratec and ChrisR : All fixed in new available version 1.21 !   :wink:

Please, test and give me feedback.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Characters tables (Alternative to the PB tool)

Post by Caronte3D »

Now works as expected :wink:
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Characters tables (Alternative to the PB tool)

Post by ChrisR »

And perfect for the buttons height when resizing :)
Merci

For the É in my name, I have been using ALT+0201 for years. Thanks to your tool, I discover that ALT+144 works too.
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

Re: Characters tables (Alternative to the PB tool)

Post by boddhi »

@ChrisR
In my name and first name, I have two É. Which led me to use ALT+144 since a long time (Yes, I'm not very young!) :) :wink:
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Characters tables (Alternative to the PB tool)

Post by ChrisR »

Off topic! in fact, I don't really use ALT+0201 (or ALT+144) much now.
I now use the top left key under Escape, which I almost never use for the ²

And I made ~ the same program for my son's laptop which broke the letter R, not really great but the keyboard is too expensive to replace.
When he is at home, he uses an external keyboard to play his games, the hook, launched at startup, does not bother, the R key remains active.

Code: Select all

EnableExplicit

#KEYEVENTF_UNICODE = $0004

Procedure.l KeyProc(nCode, wParam, lParam)
  Protected *keyInput.KBDLLHOOKSTRUCT = lParam
  Protected Result
  
    If nCode = #HC_ACTION 
      If *keyInput\vkCode = 222   ; Key at the top left under Escape: ² (which is of very little use)
        Protected InputData.INPUT
        With InputData
          \type         = #INPUT_KEYBOARD
          \ki\wScan     = 201   ; É
          \ki\dwFlags = #KEYEVENTF_UNICODE
          If wParam = #WM_KEYUP
            \ki\dwFlags | #KEYEVENTF_KEYUP
          EndIf
        EndWith
        
        SendInput_(1, @InputData, SizeOf(INPUT))
        Result = #True
      Else
        Result= CallNextHookEx_(0, nCode, wParam, lParam)  
      EndIf
    Else
      Result = CallNextHookEx_(0, nCode, wParam, lParam)
    EndIf
    ProcedureReturn Result      
EndProcedure 

Procedure SetHook()
  Protected hInstance = GetModuleHandle_(0)
  Protected Result
  If hInstance 
    Result = SetWindowsHookEx_(#WH_KEYBOARD_LL, @KeyProc(), hInstance, 0) 
  Else 
    MessageRequester("Hook", "Can't get module handle")
  EndIf
  ProcedureReturn Result  
EndProcedure 

Procedure KillHook(myKeyHook)
   ProcedureReturn UnhookWindowsHookEx_(myKeyHook)
EndProcedure 

Procedure AddSysTray()
  ; Load Icon directly from the executable resource 
  Protected hInstance = GetClassLongPtr_(WindowID(0), #GCL_HMODULE)
  Protected IconhWnd = LoadIcon_(hInstance, 1)
  If IconhWnd
    AddSysTrayIcon(1, WindowID(0), IconhWnd)
  ; Uncomment the 3 lines below, if compiled without icon
  ;Else  
  ;  UsePNGImageDecoder()
  ;  AddSysTrayIcon(1, WindowID(0), LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png"))
  EndIf
  SysTrayIconToolTip(1, "Remap Key ² to É")
  
  If CreatePopupMenu(0)  
    MenuItem(0, "Exit")
    MenuBar()
  EndIf
EndProcedure

Define myKeyHook = SetHook()
If myKeyHook
  
  If OpenWindow(0, -10, -10, 0, 0,"", #PB_Window_Tool | #PB_Window_Invisible)
    AddSysTray()
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_SysTray
          Select EventType()
            Case #PB_EventType_LeftClick, #PB_EventType_RightClick   
              DisplayPopupMenu(0, WindowID(0))
          EndSelect
          
        Case #PB_Event_Menu
          If EventMenu() = 0
            Break          
          EndIf
      EndSelect
    ForEver
  EndIf
  
  If KillHook(myKeyHook)
    myKeyHook = 0
  EndIf
EndIf
deeproot
Enthusiast
Enthusiast
Posts: 269
Joined: Thu Dec 17, 2009 12:00 pm
Location: Llangadog, Wales, UK
Contact:

Re: Characters tables (Alternative to the PB tool)

Post by deeproot »

@boddhi - looks like a very nice tool. Please continue development with it :)

Just a couple of comments :
boddhi wrote: Tue Jan 31, 2023 3:27 pm
  1. Due to a PB limitation, only characters whose ASCII value is les than 65537 are correctly handled.
  2. For those which are not displayed correctly in the tool, their use (via the copy of the symbol) nevertheless remains usable on other applications such as Word, Excel, Web editors,...
I will look soon if I can find and include a font that solves this problem.
I personally do not think the the display of characters above 65537 is a "PB limitation" - you can happily show such characters if an appropriate font is used. A Unicode surrogate pair of characters is needed for the correct display - this has already been perfectly solved by the experts here, see - viewtopic.php?p=482622&hilit=surrogate+ ... de#p482622

The are are number of fonts with excellent Unicode coverage, my favourite is the DejaVu family which is under a free licence. There is also Junicode, Linux Libertine, the Noto family and others. One problem you may have is that the chosen font may not exist on the end-user system, but you could consider embedding the font in your program so that it always displays correctly. Of course the user will still need a suitable font to show specific characters in other applications.

A while back I wrote a tool with some similarities but a very different purpose and history. Not a character table but a "minimal" easy method for end-users to type accents and other awkward characters into applications. An extended edition for "techies" gives options to output in various code formats. It's still very popular with Windows users due to being non-intrusive and portable - thanks to PureBasic of course!

Image
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Characters tables (Alternative to the PB tool)

Post by infratec »

In general it has still the same problem.

But I found the solution.

You have to rename all files (more or less).

If you rename the language file to
TablesCaractères-lang.xml
Then you have to rename the exe file to
TablesCaractères.exe
Or if you want to rename only the lang file you have to rename it to
TablesCaractères-v121-lang.xml
So please remove the vXXX stuff from the exe file name in the ZIP file.
Or rename the lang files already accordingly.
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

Re: Characters tables (Alternative to the PB tool)

Post by boddhi »

@deeproot
deeproot wrote: @boddhi - looks like a very nice tool. Please continue development with it :)
Thanks a lot for you support :wink:
deeproot wrote: I personally do not think the the display of characters above 65537 is a "PB limitation" [..]
Thanks. I will study this...

But what I meant by a limitation due to PB is the following problem:

Code: Select all

Define.s Char="🝱"
Define.l ASCIICode=Asc(Char)

Debug "String : "+Char+" (Decimal code : 128881)"
Debug "ASCII code : "+ASCIICode
Debug "Chr(ASCII code) : "+Chr(ASCIICode)
deeproot wrote: The are are number of fonts with excellent Unicode coverage [...]
I planned to manage the display font (I had already mentioned it on the French forum  :) ). This will likely be part of one of the next updates :wink: .
I just need to find the right font. I'll take a look at the ones you told me about.
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

Re: Characters tables (Alternative to the PB tool)

Post by boddhi »

@infratec

I hope to have fixed, once and for all, this localization problem with the new version 2.00.
Test and tell me if it's ok...
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

Characters tables (Alternative to the PB tool)

Post by boddhi »

New version 2.00 :
• Addition of color lists with almost 1000 colors and with, among others, their RGB, HSL, HTML codes and HTML entities
• Fixed a bug related to localization
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

Characters tables (Alternative to the PB tool)

Post by boddhi »

New version 2.10 :
  • Management of a favorite list of characters added (Please, read 'A lire - Readme.txt' file)
  • Storage of the coordinates/dimensions of the window and the widths of the lists columns added
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Characters tables (Alternative to the PB tool)

Post by idle »

You can use these to do surrogate pairs

Code: Select all

Procedure.s _Chr(v.i) ;return a proper surrogate pair for unicode values outside the BMP (Basic Multilingual Plane)
    Protected high, low
    If v < $10000
      ProcedureReturn Chr(v)
    Else
      v - $10000
      high = (v >> 10) + $D800  ;high/lead surrogate value
      low = (v & 1023) + $DC00  ;low/tail surrogate
      ProcedureReturn Chr(high) + Chr(low)
    EndIf
  EndProcedure
  
  Procedure _Asc(s.s) 
    Protected high,low 
    Protected *chr.unicode = @s 
    
    high = *chr\u
    If (high > $D7FF And high < $DBFF)  
      *chr+2 
      low = *chr\u 
      If (low & $DC00) = $DC00  
        ProcedureReturn (high - $D800) << 10 + (low - $DC00) + $10000 ;return decoded surrogate pair
      EndIf   
    EndIf   
    ProcedureReturn high
    
  EndProcedure
deeproot
Enthusiast
Enthusiast
Posts: 269
Joined: Thu Dec 17, 2009 12:00 pm
Location: Llangadog, Wales, UK
Contact:

Re: Characters tables (Alternative to the PB tool)

Post by deeproot »

idle wrote: Wed Feb 08, 2023 8:34 am You can use these to do surrogate pairs

:) That looks like the code I used a while back - perfect solution and I remember the forum discussions were really helpful in understanding more about Unicode. As always - very grateful to all you experts!
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

Re: Characters tables (Alternative to the PB tool)

Post by boddhi »

@idle
Thanks a lot for these great tricks that helped me improve my code. :wink:
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Characters tables (Alternative to the PB tool)

Post by idle »

Those codes are one I modified from demivec, unicode is complicated.
Post Reply