@@ -11,6 +11,7 @@ char textBuffer[1024] = { 0 };
1111char phoneKeyBuffer[1024 ];
1212
1313time_t lastPressTime = 0 ;
14+ time_t lastPhoneLetterTime = 0 ;
1415int keyIndex = 0 ;
1516int lastKey = -1 ;
1617
@@ -19,8 +20,12 @@ HWND windowHandle = 0;
1920LPCWSTR text = L" " ;
2021LPCWSTR hintText = L" " ;
2122std::string hintTextStr = " " ;
22- int hintTextIndex = 0 ;
23- int hintTextLength = 0 ;
23+ int hintTextIndex1 = 0 ;
24+ int hintTextLength1 = 0 ;
25+ int hintTextIndex2 = 0 ;
26+ int hintTextLength2 = 0 ;
27+ int textIndex1 = 0 ;
28+ int textLength1 = 0 ;
2429int t9WordIndex = 0 ;
2530ULONGLONG lastTS = 0 ;
2631bool isShowing = false ;
@@ -70,7 +75,7 @@ void findT9Word()
7075 phoneKeyNode->next = 0 ;
7176 phoneKeyNode->children = {0 };
7277
73- Node* Children[31 ] = { 0 };
78+ Node* Children[NUM_CHILDREN_TO_GET ] = { 0 };
7479 int start = 0 ;
7580 if (strlen (phoneKeyNode->word ) > 0 )
7681 {
@@ -80,9 +85,9 @@ void findT9Word()
8085 {
8186 start = 1 ;
8287 }
83- getTenChildrenWithWords (wordNode, &Children[1 ]);
88+ getChildrenWithWords (wordNode, &Children[1 ]);
8489 int lastIndex = 0 ;
85- for (int i = start; i < 30 ; i++)
90+ for (int i = start; i < NUM_CHILDREN_TO_GET ; i++)
8691 {
8792 Node* currentNode = Children[i];
8893 if (currentNode && currentNode->word )
@@ -92,22 +97,36 @@ void findT9Word()
9297 }
9398 if (t9WordIndex > lastIndex)
9499 t9WordIndex = lastIndex;
95- for (int i = start; i < 30 ; i++)
100+ for (int i = start; i < NUM_CHILDREN_TO_GET ; i++)
96101 {
97102 Node* currentNode = Children[i];
98103 if (!currentNode)
99104 continue ;
100105 if (currentNode && currentNode->word )
101106 {
102- printf (" currentNode: %s\n " , currentNode->word );
103107 if (i == t9WordIndex)
104108 {
105- hintTextIndex = hintTextStr.length () + 1 ;
106- hintTextLength = strlen (currentNode->word );
109+ hintTextIndex1 = hintTextStr.length () + 1 ;
110+ hintTextLength1 = strlen (currentNode->word );
107111 selectedNode = currentNode;
112+ if (i == 0 )
113+ {
114+ hintTextIndex2 = keyIndex;
115+ hintTextLength2 = 1 ;
116+ textIndex1 = 0 ;
117+ textLength1 = 0 ;
118+ }
119+ else
120+ {
121+ hintTextIndex2 = 0 ;
122+ hintTextLength2 = 0 ;
123+ textIndex1 = 0 ;
124+ textLength1 = strlen (t9Numbers);
125+ }
108126 }
109127 hintTextStr = hintTextStr + " " + currentNode->word ;
110128 }
129+
111130 }
112131 if (selectedNode && selectedNode->word ) {
113132
@@ -124,17 +143,18 @@ void findT9Word()
124143 strcpy_s (textBuffer, sizeof (textBuffer), selectedNode->word );
125144 }
126145
127- if (hintTextIndex > 12 )
146+ if (hintTextIndex1 > 12 )
128147 {
129- hintTextStr = hintTextStr.substr (hintTextIndex - 12 );
130- hintTextIndex = 12 ;
148+ hintTextStr = hintTextStr.substr (hintTextIndex1 - 12 );
149+ hintTextIndex1 = 12 ;
131150 }
132151}
133152
134153void phoneKey (uint8_t key)
135154{
136155 time_t currentTime = time (NULL );
137- double seconds = difftime (currentTime, lastPressTime); // Get the time since the last keypress
156+ double seconds = difftime (currentTime, lastPhoneLetterTime); // Get the time since the last keypress
157+ lastPhoneLetterTime = currentTime;
138158 if (seconds < 2 && strlen (phoneKeyBuffer) > 0 && lastKey == key)
139159 {
140160 ++keyIndex %= strlen (phoneKeys[key]); // Cycle through characters in the string
@@ -379,6 +399,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
379399 {
380400 time_t currentTime = time (NULL );
381401 double seconds = difftime (currentTime, lastPressTime); // Get the time since the last keypress
402+ double phoneKeySeconds = difftime (currentTime, lastPhoneLetterTime); // Get the time since the last keypress
382403 if (!isShowing && seconds < 2 )
383404 {
384405 ShowWindow (windowHandle, SW_NORMAL);
@@ -387,25 +408,41 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
387408 isShowing = true ;
388409 }
389410 Rectangle (hDC, 0 , 0 , GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN));
390- if (seconds < 2 )
411+ if (seconds < 4 )
391412 {
392413 SetTextColor (hDC, RGB (50 , 230 , 70 ));
393414 SelectObject (hDC, hintFont);
394415 hintDest.left = 0 ;
395416 DrawText (hDC, hintText, (int )wcslen (hintText), &hintDest, 0 );
396417 SetTextColor (hDC, RGB (200 , 60 , 35 ));
397418
398- if (hintTextIndex < wcslen (hintText))
419+ if (hintTextIndex1 < wcslen (hintText))
420+ {
421+ SIZE sz;
422+ GetTextExtentPoint32 (hDC, hintText, hintTextIndex1, &sz);
423+ hintDest.left = sz.cx ;
424+ DrawText (hDC, &hintText[hintTextIndex1], hintTextLength1, &hintDest, 0 );
425+ }
426+ if (hintTextIndex2 < wcslen (hintText) && phoneKeySeconds < 2 )
399427 {
400428 SIZE sz;
401- GetTextExtentPoint32 (hDC, hintText, hintTextIndex , &sz);
429+ GetTextExtentPoint32 (hDC, hintText, hintTextIndex2 , &sz);
402430 hintDest.left = sz.cx ;
403- DrawText (hDC, &hintText[hintTextIndex ], hintTextLength , &hintDest, 0 );
431+ DrawText (hDC, &hintText[hintTextIndex2 ], hintTextLength2 , &hintDest, 0 );
404432 }
405433 }
406434 SelectObject (hDC, font);
407435 SetTextColor (hDC, RGB (50 , 230 , 70 ));
436+ dest.left = 0 ;
408437 DrawText (hDC, text, (int )wcslen (text), &dest, 0 );
438+ if (textIndex1 < wcslen (text))
439+ {
440+ SetTextColor (hDC, RGB (200 , 60 , 35 ));
441+ SIZE sz;
442+ GetTextExtentPoint32 (hDC, text, textIndex1, &sz);
443+ dest.left = sz.cx ;
444+ DrawText (hDC, &text[textIndex1], textLength1, &dest, 0 );
445+ }
409446 CreateThread (nullptr , 0 , [](void *) -> DWORD
410447 {
411448 Sleep (2000 );
0 commit comments