Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Touch keyboard 1

Status
Not open for further replies.

florindaniel

Programmer
Dec 4, 2009
120
0
0
RO
Hello,

I would like to use the native Touch keyboard on a touch-screen computer running win8.1 whenever I setfocus to a textbox.

i.e. whenever that textbox gets the focus I would like touch keyboard automatically popup and then dissapear
on LostFocus, without pressing the keyb icon.

Any ideas?

Thank you,
Daniel
 
I don't have Windows 8, but I hope these demos would give you some hints.

1. Using a thirty party software
Download a free small virtual keyboard from
Code:
Declare Integer ShellExecute In shell32 Integer hWindow, String lpOperation, String lpFile, String lpParameters, String lpDirectory, Integer nShowCmd
Declare Integer SetParent In User32 Integer HWnd, Integer ParenthWnd
Declare Integer FindWindow In user32 String lpClassName, String lpWindowName
Declare Integer GetWindowLong In user32 Integer HWnd, Integer nIndex
Declare Integer SetWindowLong In user32 Integer HWnd, Integer nIndex, Integer dwNewLong
Declare Integer SetFocus In user32 Integer
Declare Integer SetWindowPos In user32 INTEGER HWnd, INTEGER hWndInsertAfter, INTEGER x, INTEGER Y, INTEGER cx, INTEGER cy, INTEGER uFlags
Declare Integer GetWindowThreadProcessId in Win32API Integer hWnd, Integer @lpdwProcessId
Declare Integer OpenProcess in Win32API Integer dwDesiredAccess, Integer bInheritHandle, Integer dwProcessID
Declare Integer TerminateProcess in Win32API Integer hProcess, Integer uExitCode

Clear
Public ofrm
ofrm = Createobject("MyForm")
ofrm.Show()

Define Class MyForm As Form
	Width = 900
	Height=430
	hOsk = 0
	nOskHeight = 200
	ShowWindow = 2
	Desktop = .T.
	AutoCenter = .T.
	Add Object txt1 As TextBox
	Add Object cmd1 As CommandButton With Top = 50 , Caption = "\<Click"
	Add Object txt2 As TextBox WITH top = 100
	Add Object cmd2 As CommandButton With Top = 150 , Caption = "\<Click"
	Add Object tmr As Timer With Interval = 300,Enabled = .F.
	
	PROCEDURE Init
		BINDEVENT(This.txt1,'GotFocus',This,'MyGotFocus')
		BINDEVENT(This.txt2,'GotFocus',This,'MyGotFocus')
		BINDEVENT(This.txt1,'LostFocus',This,'MyLostFocus')
		BINDEVENT(This.txt2,'LostFocus',This,'MyLostFocus')
	PROCEDURE Mygotfocus
		IF ThisForm.hosk = 0
			ThisForm.tmr.Enabled = .T.
		ELSE
			SetWindowPos(ThisForm.hOsk, 0, 0, SYSMETRIC(2)-ThisForm.nOskHeight,SYSMETRIC(1), ThisForm.nOskHeight,  0x0010+0x0040) && move to the bottom of the form and show
		ENDIF
	ENDPROC
	PROCEDURE Mylostfocus
		SetWindowPos(ThisForm.hOsk, 0, 0, SYSMETRIC(2)-ThisForm.nOskHeight,SYSMETRIC(1), ThisForm.nOskHeight,  0x0010+0x0080) && move to the bottom of the form and show
	ENDPROC
	Procedure Load
		= ShellExecute(0, "open", "d:\kit\freevk.exe", "", "", 1) &&& the path can be generalised
	ENDPROC
	
	Procedure tmr.Timer
		LOCAL nStyle
		ThisForm.hOsk = FindWindow (.Null., "Free Virtual Keyboard ([URL unfurl="true"]www.FreeVirtualKeyboard.com)")[/URL]
		nStyle = GetWindowLong (ThisForm.hOsk, -16)
		**************************************************************************************************************
		* If you want the keyboard to be embeded in your form
		* uncomment the following 4 lines
		* and in all SetWindowPos() change SYSMETRIC(2) with Thisform.height and SYSMETRIC(1) with Thisform.width
		**************************************************************************************************************
*!*			SetWindowLong (ThisForm.hOsk, -16, Bitset(m.nStyle,30)) && set child
*!*			SetWindowLong (ThisForm.hOsk, -16, Bitclear(m.nStyle,31)) && remove popup
*!*			SetParent(ThisForm.hOsk, Thisform.HWnd) && change parent
*!*			SetWindowLong (ThisForm.hOsk, -16, BITAND(m.nStyle,2^32-1-0xCF0000)) && remove the title bar
		SetWindowPos(ThisForm.hOsk, 0, 0, SYSMETRIC(2)-ThisForm.nOskHeight,SYSMETRIC(1), ThisForm.nOskHeight,  0x0010+0x0040) && move to the bottom of the form and show

		This.Enabled = .F.
	ENDPROC
	PROCEDURE destroy
		LOCAL lnProcessID
		UNBINDEVENTS(This)
		lnProcessID = 0
		GetWindowThreadProcessId(ThisForm.hOsk, @lnProcessID)
		TerminateProcess(OpenProcess(1, 1, m.lnProcessID) , 0)
	ENDPROC
Enddefine

2. Using osk.exe on a 32bit Windows
Windows XP, 7 and 8 are shifted with On-creen keyboard
On a 32 bit system you can use the above code but execute osk.exe instead freevk.exe, i.e :
= ShellExecute(0, "open", "osk.exe", "", "", 1)
and when search the window, type its caption (if the system is in English)
ThisForm.hOsk = FindWindow (.Null., "On-Screen Keyboard")

3. Using osk.exe on a 64bit Windows
On a 64bit Windows, osk.exe can be launched, but cannot be controlled from within VFP, because VFP is 32 bit and osk.exe is 64bit
Code:
Declare Integer ShellExecute In shell32 Integer hWindow, String lpOperation, String lpFile, String lpParameters, String lpDirectory, Integer nShowCmd
Declare Integer ShowWindow In user32 Integer hWindow, Integer nCmdShow
DECLARE integer Wow64DisableWow64FsRedirection IN kernel32 Long @
DECLARE integer Wow64RevertWow64FsRedirection IN kernel32 Long @

Public ofrm
ofrm = Createobject("MyForm")
ofrm.Show()

Define Class MyForm As Form
	hwndosk = -1
	ADD OBJECT txt1 as textbox
	ADD OBJECT cm1 as commandbutton WITH top = 50
	ADD OBJECT txt2 as textbox WITH top = 100
	ADD OBJECT cm2 as commandbutton WITH top = 150
	PROCEDURE Load
		LOCAL lnVal
		IF LEN(GETENV("ProgramFiles(x86)"))>1
			xxx=Wow64DisableWow64FsRedirection(lnVal)
		ENDIF
		ThisForm.hwndosk = ShellExecute(0, "open", "osk.exe", "", "", 1)
		IF LEN(GETENV("ProgramFiles(x86)"))>1
			xxx=Wow64RevertWow64FsRedirection(lnVal)
		ENDIF
	ENDPROC
ENDDEFINE

A detailed discussion can be found here
Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top