LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Need example or solution of source code using caps lock.

Hi,

Need help urgently. I'm thinking of source code which can help me to auto and immediate converting the character whenever I key in the keyboard instead of press Enter to convert it. Your help much appreciate.

Regards,
The Griffin
0 Kudos
Message 1 of 4
(2,857 Views)
Where is the input coming from?
If it's a Textbox, create a callback for the Textbox, add a case for EVENT_KEYPRESS where you call GetCtrlVal to read the Textbox contents, then call the ANSI C function toupper() to convert it, and call SetCtrlVal to rewrite the value.
Message 2 of 4
(2,850 Views)
OK, so it was a little more complicated than my quicky note. Here's some more details and a sample project.
In the textbox callback, you need to check EVENT_VAL_CHANGED, not EVENT_KEYPRESS. KEYPRESS occurs before the value is updated.
Then, with a textbox, call ResetTextBox to update the text, not SetCtrlVal (which appends to a textbox).
If you want to catch a keystroke anywhere in the textbox, you need to call GetCtrlAttribute to find the cursor position (ATTR_TEXT_SELECTION_START), and SetCtrlAttribute when you're done to restore the original cursor position (lost on a call to ResetTextBox).
Is that better?
Look at the attached sample project which lets you choose upper case, lower case, or mixed.
0 Kudos
Message 3 of 4
(2,836 Views)
Actually, if all you need to do is change the characters one at a time, you should be able to use EVENT_KEYPRESS. Instead of using GetCtrlVal to get the character that was pressed, you would get it from the eventdata1 parameter passed to the callback function (using the GetKeyPressEventCharacter function). Then, after calling toupper(), simply call the SetKeyPressEventKey function to change the key that the textbox will receive (this is stored in eventdata2).

Luis
NI
0 Kudos
Message 4 of 4
(2,831 Views)