Author Topic: International Characters Input Routine  (Read 7544 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

FellippeHeitor

  • Guest
International Characters Input Routine
« on: September 25, 2018, 02:19:46 pm »
This is limited to the accented characters available in the builtin ascii table. Hit the accent, then hit the letter.

´ + a should result in á.

No warranties. Tested on a Windows machine set to Brazilian Portuguese.

Code: QB64: [Select]
  1. DIM replEntries AS LONG
  2. REDIM replTableSource(1 TO 100) AS STRING, replTableDest(1 TO 100) AS STRING
  3. RESTORE replTable
  4. i& = 0
  5.     READ a$
  6.     IF a$ = "**END**" THEN EXIT DO
  7.     READ b%
  8.     i& = i& + 1
  9.     IF i& > UBOUND(replTableSource) THEN
  10.         REDIM _PRESERVE replTableSource(1 TO UBOUND(replTableSource) + 100) AS STRING
  11.         REDIM _PRESERVE replTableDest(1 TO UBOUND(replTableDest) + 100) AS STRING
  12.     END IF
  13.     replTableSource(i&) = a$
  14.     replTableDest(i&) = CHR$(b%)
  15.     replEntries = replEntries + 1
  16.  
  17. ON TIMER(.4) GOSUB blinkCursor
  18.  
  19. PRINT "International Characters Input Routine"
  20. row = CSRLIN
  21.     GOSUB showText
  22.     GOSUB showCursor
  23.  
  24.     k& = _KEYHIT
  25.  
  26.     SELECT CASE k&
  27.         CASE -222
  28.             IF _KEYDOWN(100303) OR _KEYDOWN(100304) THEN 'shift
  29.                 IF LEN(nextAccent$) > 0 THEN
  30.                     nextChar$ = nextAccent$ + "^"
  31.                 ELSE
  32.                     nextAccent$ = "^"
  33.                 END IF
  34.             ELSE
  35.                 IF LEN(nextAccent$) > 0 THEN
  36.                     nextChar$ = nextAccent$ + "~"
  37.                     nextAccent$ = ""
  38.                 ELSE
  39.                     nextAccent$ = "~"
  40.                 END IF
  41.             END IF
  42.         CASE -219
  43.             IF _KEYDOWN(100303) OR _KEYDOWN(100304) THEN 'shift
  44.                 IF LEN(nextAccent$) > 0 THEN
  45.                     nextChar$ = nextAccent$ + "`"
  46.                     nextAccent$ = ""
  47.                 ELSE
  48.                     nextAccent$ = "`"
  49.                 END IF
  50.             ELSE
  51.                 IF LEN(nextAccent$) > 0 THEN
  52.                     nextChar$ = nextAccent$ + "'"
  53.                     nextAccent$ = ""
  54.                 ELSE
  55.                     nextAccent$ = "'"
  56.                 END IF
  57.             END IF
  58.         CASE 32 TO 126, 209, 241, 199, 231
  59.             nextChar$ = nextAccent$ + CHR$(k&)
  60.             nextAccent$ = ""
  61.         CASE 8
  62.             IF LEN(text$) > 0 THEN text$ = LEFT$(text$, LEN(text$) - 1)
  63.         CASE 13
  64.             GOSUB showText
  65.             cursor = 0
  66.             GOSUB showCursor
  67.             text$ = ""
  68.             row = row + 1
  69.     END SELECT
  70.  
  71.     FOR i = 1 TO replEntries
  72.         IF replTableSource(i) = nextChar$ THEN
  73.             nextChar$ = replTableDest(i)
  74.             EXIT FOR
  75.         END IF
  76.     NEXT
  77.     text$ = text$ + nextChar$
  78.     IF LEN(nextChar$) > 0 THEN nextChar$ = "": nextAccent$ = ""
  79.     _LIMIT 30
  80.  
  81. blinkCursor:
  82. cursor = NOT cursor
  83.  
  84. showText:
  85. LOCATE row, 1
  86. PRINT text$;
  87.  
  88. showCursor:
  89. IF cursor THEN PRINT "_ " ELSE PRINT "  "
  90.  
  91. replTable:
  92. DATA ^a,131,"'a",160,`a,133
  93. DATA "'E",144
  94. DATA ^e,136,"'e",130,`e,138
  95. DATA "'i",161,`i,141
  96. DATA ^o,147,"'o",162,`o,149
  97. DATA ^u,150,"'u",163,`u,151
  98. DATA ~N,165,Ñ,165,~n,164,ñ,164
  99. DATA "'C",128,"'c",135
  100. DATA Ç,128,ç,135
  101. DATA **END**
« Last Edit: September 25, 2018, 02:23:38 pm by FellippeHeitor »

Offline freetrav

  • Newbie
  • Posts: 45
    • View Profile
Re: International Characters Input Routine
« Reply #1 on: September 25, 2018, 03:50:36 pm »
Why would I use this instead of simply loading the appropriate keyboard driver at the OS level?

(I have my Windows and Linux keyboards set to US-International, by default.)

FellippeHeitor

  • Guest
Re: International Characters Input Routine
« Reply #2 on: September 25, 2018, 03:52:58 pm »
If you won't ever need international characters to be input, you won't use this.

If you've ever tried entering international characters into a QB64 program, you'll know why this could be useful, as there is no support for this natively currently, even if your OS is properly set.

Marked as best answer by on Today at 03:12:42 am

Offline freetrav

  • Newbie
  • Posts: 45
    • View Profile
Re: International Characters Input Routine
« Reply #3 on: September 26, 2018, 07:13:10 am »
  • Undo Best Answer
  • Indeed, you appear to be correct - but the question now becomes why QB64 doesn't honor the OS setting?