The present invention relates to the field of computers, and in particular, to a character input prompting method and electronic device.
At present, most input methods support word input, and also support sentence input. However, when editing a document, a user often needs to make a modification at a certain position in the middle of a sentence. In current input methods, the user has to move a cursor to a modification position and then in the same way as sequential input, inputs a code through a method such as Pinyin or Wubi; and only in this way, a character that needs to be added or modified can be inserted into the sentence. Such a process may require the user to use a mouse and a keyboard in combination to achieve a purpose of modification. The process is complex, thereby reducing a text editing processing speed of an electronic device.
Embodiments of the present invention provide a character input prompting method and electronic device, so that a modification or insertion process can be simpler, thereby improving a text editing processing speed of an electronic device.
Embodiments of the present invention adopt the following technical solutions:
In one aspect, an embodiment of the present invention provides a character input prompting method, where the method includes:
In another aspect, an embodiment of the present invention provides an electronic device, where the electronic device includes:
The embodiments of the present invention provide a character input prompting method and electronic device. A position of a cursor can be detected, and characters before and after the cursor are obtained; and then an input method database is searched for a character grammatically associated with the characters before and after the cursor and a user is prompted, in the form of a list, for the character grammatically associated with the characters before and after the cursor, so that the user can perform selection, and a modification or insertion process is simpler, thereby improving a text editing processing speed of an electronic device.
To describe the technical solutions in the embodiments of the present invention more clearly, the accompanying drawings required for describing the embodiments or are introduced briefly in the following. Apparently, the accompanying drawings in the following description show only some embodiments of the present invention, and persons of ordinary skill in the art may also obtain other drawings according to these accompanying drawings without creative efforts.
The technical solutions in the embodiments of the present invention are clearly described in the following with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the embodiments to be described are only a part rather than all of the embodiments of the present invention. All other embodiments obtained by persons of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
The terms used in the embodiments of the present invention are only used to describe specific embodiments, but are not intended to limit the present invention. Unless otherwise specified clearly in the context, the words “one”, “the”, and “said” in a singular form used in the embodiments of the present invention and the appended claims also imply a plural form semantically. It should also be noted that, the term “and/or” used in this application refers to and includes any one or all possible combinations of the listed one or more associated items.
Embodiment 1 of the present invention provides a character input prompting method. As shown in
S101: Obtain a position of a cursor.
S102: Obtain a first character before the position of the cursor and adjacent to the cursor and a second character after the position of the cursor and adjacent to the cursor, where the first character is a single character or a character string including multiple characters, and the second character is a single character or a character string including multiple characters.
S103: Obtain, from an input method database, a character grammatically associated with at least one of: the first character and the second character.
S104: Prompt, in the form of a candidate character list, a user for the character grammatically associated with at least one of: the first character and the second character.
The embodiment of the present invention provides a character input prompting method. A position of a cursor can be detected, and characters before and after the cursor are obtained; and then an input method database is searched for a character grammatically associated with the characters before and after the cursor and a user is prompted, in the form of a list, for the character grammatically associated with the characters before and after the cursor, so that the user can perform selection, and a modification or insertion process is simpler, thereby improving a text editing processing speed of an electronic device.
Embodiment 2 of the present invention provides a character input prompting method. As shown in
S201: Obtain a position of a cursor according to a preset trigger condition.
Exemplarily, first of all, when an electronic device detects that a cursor stops moving, the electronic device detects retention duration of the cursor; and when it is detected that the retention duration of the cursor reaches preset duration, the electronic device determines that the current position of the cursor requires modification or insertion, and obtains the current position of the cursor.
Alternatively, according to a cursor position obtaining instruction received from a user, the position of the cursor may be obtained by executing the cursor position obtaining instruction. In this case, the user may use a shortcut key on a keyboard to generate the cursor position obtaining instruction, and may also long press a left mouse button or a right mouse button to generate the cursor position obtaining instruction. The electronic device obtains the current position of the cursor after receiving the cursor position obtaining instruction.
Definitely, two trigger manners may also be combined. After the cursor stops moving, the electronic device starts detecting retention duration of the cursor. If the retention duration of the cursor does not reach the preset duration, the current position of the cursor is immediately obtained upon receiving a cursor position obtaining instruction from the user; and if no cursor position obtaining instruction is received from the user, the current position of the cursor is obtained when the retention duration of the cursor reaches the preset duration.
Further, in addition to the foregoing trigger manners, a microphone may also be used to trigger, through sound, the obtaining of the position of the cursor; or a camera of the electronic device may be used to trigger, through a special gesture, the obtaining of the position of the cursor.
Exemplarily, a coordinate of the current position of the cursor may be obtained by using a GetCaretPos function, and a coordinate of the current position of the cursor may also be obtained by using a GetGUIThreadInfo function. In consideration of the universality of a system and software, the latter is recommended.
S202: Obtain a first character before the position of the cursor and adjacent to the cursor and a second character after the position of the cursor and adjacent to the cursor.
Exemplarily, after the position of the cursor is obtained through detection, the first character is obtained by performing character obtaining backwards from the position of the cursor to a text control character; and the second character is obtained by performing character obtaining forwards from the position of the cursor to a text control character.
The text control character includes: a punctuation mark, a carriage return, and a line break. For example, if the cursor is located in the middle of a paragraph, the first character is obtained by performing character obtaining backwards from the position of the cursor to a punctuation mark; and the second character is obtained by performing character obtaining forwards from the position of the cursor to a punctuation mark. If the cursor is located at the beginning of a paragraph, character obtaining is performed backwards from the position of the cursor to a carriage return, and in this case, the first character is null. If a sentence where the cursor is located is not finished and no punctuation mark follows the position of the cursor, the second character is obtained by performing character obtaining forwards from the position of the cursor to a carriage return.
For example, in an operating system of the electronic device, an API (Application Programming Interface, application programming interface) function and a TextOut (output) function need to be invoked for output and display of all text. Therefore, characters before and after the position of the cursor may be obtained by adopting a manner of establishing a hook (Hook) with the API function.
First, an address of the TextOut function is found by searching a memory space of the system; and then, parameters of the TextOut function are transferred to a target function, and the cursor of the electronic device jumps to the target function. The target function is used for word selection of the cursor, and the parameters of the TextOut function include: HDC hdc, int nXStart, int nYStart, LPCTSTR lpString, and int cbString.
The system may run multiple windows for editing text at the same time, and therefore, after the cursor of the electronic device jumps to the target function, the target function first determines whether a window that requires character obtaining is a current window; if yes, character obtaining is performed; and otherwise, no processing is performed.
Exemplarily, after the cursor of the electronic device jumps to the target function, the electronic device determines, by using the target function, whether the HDC hdc is a window handle of the current position of the cursor. The electronic device may open multiple windows at the same time, and therefore, it is determined whether the HDC hdc is a window handle of the current position of the cursor, so as to identify whether the cursor is located in a current operating window. If the HDC hdc is not a window handle of the current position of the cursor, no processing is performed; and if the HDC hdc is a window handle of the current position of the cursor, the target function copies the parameters of the TextOut function, where the int nXStart and int nYStart represent coordinates of an output character of the TextOut function, and the LPCTSTR lpString represents content of the output character. After the copy is completed, the cursor returns from the target function to the TextOut function, and the TextOut function is continued to be executed, so that an output character of the current window can be displayed normally.
Afterward, according to the coordinates of the output character, namely, the int nXStart and int nYStart, and the content of the output character, namely, the LPCTSTR lpString, and in combination with the current position of the cursor, character obtaining is performed backwards from the position of the cursor to a punctuation mark and character obtaining is also performed forwards from the position of the cursor to a punctuation mark by using the target function. In this way, the first character before the position of the cursor and the second character after the position of the cursor are both obtained.
Further, to avoid that an obtained character is too long, a preset character length may be set in the electronic device to serve as an upper limit for the length of the obtained character.
In this way, character obtaining is performed backwards from the position of the cursor, and if no text control character is obtained but the length of an obtained character reaches the preset character length, the obtaining is stopped to obtain the first character.
In the same way, character obtaining is performed forwards from the position of the cursor, and if no text control character is obtained but the length of an obtained character reaches the preset character length, the obtaining is stopped to obtain the second character.
The first character may be a single character or a character string including multiple characters; and the second character may be a single character or a character string including multiple characters. In other words, the first character may be a character, may also be a word, and may also be a sentence; and in the same way, the second character may be a character, may also be a word, and may also be a sentence.
S203: Obtain, from an input method database, a character grammatically associated with at least one of: the first character and the second character.
First, starting from a character, which is closest to the position of the cursor, of the obtained first character, characters are added backwards one by one, and fuzzy matching is performed between the characters that are added backwards one by one and characters in the input method database, where the input method database includes a character library, a word library, and a sentence library, until matching for all of the first character is finished, so as to find a character that can form a word with the first character or a character that can form a sentence with the first character, where the character may be a single character or a character string including multiple characters, that is, the character may be a character, a word, or a sentence.
Exemplarily, in the first character, fuzzy matching is performed between a character in first place before the position of the cursor and a character, a word, and a sentence in the input method database, so as to find a character that can form a word with the character in first place or a character that can form a sentence with the character in first place. After matching for the character in first place is finished, a character is added backwards and fuzzy matching is performed between the character and a character, a word, and a sentence in the input method database, that is, fuzzy matching is performed between a character string formed by the character in first place and a character in second place before the position of the cursor and a character, a word, and a sentence in the input method database, so as to find a character that can form a word with the character string or a character that can form a sentence with the character string. The rest is done in the same manner until matching for all of the first character is finished.
In the second character, starting from a character, which is closest to the position of the cursor, of the second character, characters are added forwards one by one, and fuzzy matching is performed between the characters that are added forwards one by one and characters in the input method database, where the input method database includes a character library, a word library, and a sentence library, until matching for all of the second character is finished, so as to find a character that can form a word with the second character or a character that can form a sentence with the second character, where the character may be a single character or a character string including multiple characters, that is, the character may be a character, a word, or a sentence. A specific process is exactly the same as that of the first character, and is not described in detail herein again.
It should be noted that during the fuzzy matching, matching may be performed with the first character, may also be performed with the second character, and may also be performed with the first character and the second character at the same time. Definitely, when the matching is performed with the first character and the second character at the same time, an obtained grammatically associated character is a character that has grammatical association with both the first character and the second character, namely, a character that can form a word or a sentence with both the first character and the second character, where the character may be a single character, and may also be a character string including multiple characters. A specific matching manner may be set according to an actual requirement, which is not limited in this embodiment.
S204: Prompt, in the form of a candidate character list, a user for the character grammatically associated with at least one of: the first character and the second character.
The user is prompted for the found character that can form a word or a sentence with the first character, the found character that can form a word or a sentence with the second character, or the found character that can form a word or a sentence with the first character and the second character, and the found character may be displayed, for example, in the form of a list.
In another embodiment of the present invention, characters may be displayed in a candidate character list in descending order of a matching degree. The matching degree may be set according to the grammar; a character, word, or sentence that can form a grammatically optimal combination with the first character or the second character is displayed on the top of the list for the user to select.
Exemplarily, in a paragraph shown in
S205: Receive a third character selected by the user in the candidate character list, and display the third character at the position of the cursor, where the third character may be a single character or a character string including multiple characters, that is, the third character may be a character, may be a word, and may also be a sentence.
As shown in
Alternatively, further, when the candidate character list has only one candidate third character, the electronic device automatically displays the third character at the position of the cursor, where the third character herein may be a single character or a character string including multiple characters, that is, the third character may be a character, may be a word, and may also be a sentence; and moreover, the third character herein may be the same as and may also be different from the foregoing third character selected by the user in the candidate character list.
As shown in
When the candidate character list has multiple options, the third character that serves as the first option is displayed at the position of the cursor. The third character herein may be a single character or a character string including multiple characters, that is, the third character may be a character, may be a word, and may also be a sentence; and moreover, the third character herein may be the same as and may also be different from the foregoing third character selected by the user in the candidate character list and the third character that is the only one candidate.
As shown in
Further, before displaying “”, the electronic device may first determine whether a fourth character formed by characters before and after the position of the cursor has the same attribute as that of the third character. In a general case, the fourth character may have the same length as that of the third character, and the same attribute may refer to the same pronunciation or the same meaning.
When the fourth character has the same attribute as that of the third character, the fourth character is deleted, so that the fourth character is deleted and replaced with the third character. The fourth character may be deleted by invoking a Delete function.
For example, in a paragraph shown in
Definitely, except that there is no character deletion step, other steps of a method for inserting a character at a position where a character is missing are the same as those of the foregoing method, and are not described herein again.
The embodiment of the present invention provides a character input prompting method. A position of a cursor can be detected, and characters before and after the cursor are obtained; and then an input method database is searched for a character grammatically associated with the characters before and after the cursor and a user is prompted, in the form of a list, for the character grammatically associated with the characters before and after the cursor, so that the user can perform selection, and a modification or insertion process is simpler, thereby improving a text editing processing speed of an electronic device.
Another embodiment of the present invention provides an electronic device 1, and as shown in
The obtaining unit 12 may be specifically configured to:
Alternatively, the obtaining unit 12 may be specifically configured to:
Further, as shown in
The active inserting unit 16 is further configured to:
Further, as shown in
Further, the detecting unit 11 may be specifically configured to:
The matching unit 13 may be specifically configured to:
The prompting unit 14 may be specifically configured to:
The electronic device provided in the embodiment of the present invention can detect a position of a cursor and obtain characters before and after the cursor, then searches an input method database for a character grammatically associated with the characters before and after the cursor, and prompts, in the form of a list, a user of the character, so that the user can perform selection, and a modification or insertion process is simpler, thereby improving a text editing processing speed of an electronic device.
The electronic device 1 provided in the embodiment of the present invention is applicable to electronic devices having an input function, for example, a personal computer, a tablet computer, and a smart phone, and can execute actions in the foregoing method embodiments.
In addition, various functional units of the electronic device 1 according to each embodiment of the present invention may be integrated into one processing unit or may exist as various separate physical units, or two or more units may also be integrated into one unit. The integrated unit may be implemented in the form of hardware or in the form of a software functional unit.
The integrated unit implemented in the form of a software functional unit may be stored in a computer readable storage medium. The software functional unit is stored in a storage medium, which includes several instructions used for enabling an electronic device (which may be a personal computer, a server, or a network device) to execute part of steps of the methods in the embodiments of the present invention. The storage medium includes various media capable of storing program codes, such as a USB flash disk, a mobile hard disk, a read only memory (Read Only Memory, referred to as ROM), a random access memory (Random Access Memory, referred to as RAM), a magnetic disk, or an optical disk.
The foregoing descriptions are only specific embodiments of the present invention, but are not intended to limit the protection scope of the present invention. Any variation or replacement that can be easily figured out by persons skilled in the art within the technical scope disclosed in the present invention shall all fall within the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to that of the claims.
Number | Date | Country | Kind |
---|---|---|---|
201210181317.0 | Jun 2012 | CN | national |
This application is a continuation of International Patent Application No. PCT/CN2013/070090, filed on Jan. 6, 2013, which claims priority to Chinese Patent Application No. 201210181317.0, filed on Jun. 4, 2012, both of which are hereby incorporated by reference in their entireties.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2013/070090 | Jan 2013 | US |
Child | 14096719 | US |