Page 1 of 2
Drawing & Handwriting Objects. Great for touchscreen devices
Posted: 10 Oct 2013, 18:24
by TLM
Microsoft INKEdit object allows you to embed drawing and hand writing recognition into a GUI.
Here a simple example:
Code: Select all
Gui Add, Text,, Draw in the picture box below
Gui Add, ActiveX, xm w600 h300 vss, msinkaut.InkPicture.1
Gui Add, Text,, Use handwriting recognition below (write letters and wait a bit)
Gui Add, ActiveX, xm w600 h100 vink, InkEd.InkEdit.1
(ink.UseMouseForInput := 1), ink.InkInsertMode := 0
Gui, Show, AutoSize
Return
GuiClose:
ExitApp
There's a lot of options for saving, custom Unicode like characters etc.
More info here:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
If you have any question feel free to ask.
Re: Drawing & Handwriting Objects. Great for touchscreen dev
Posted: 11 Oct 2013, 02:21
by Learning one
Very nice TLM! Thanks for sharing!
Re: Drawing & Handwriting Objects. Great for touchscreen dev
Posted: 11 Oct 2013, 03:10
by lblb
Wow TLM, this is great! Thanks for sharing. I have been looking for something like this for quite a while.
I have two questions for you (by the way, I'm really not familiar with ActiveX stuff):
1) What do the InkEd. and .1 parts mean in "InkEd.InkEdit.1"? What do the msinkaut. and .1 parts mean in "msinkaut.InkPicture.1"? How did you know to write them like that?
2) I've been exploring the different attributes following the MSDN link you provided. A whole new world to explore for me! Everything in my test script below works great on my tablet but I can't seem to be able to modify the color and the cursor (see the two highlighted lines.) Any idea what I'm doing wrong? The info for these is here:
http://msdn.microsoft.com/en-us/library/aa514608.aspx
http://msdn.microsoft.com/en-us/library/aa514610.aspx
Thanks again for sharing this, much appreciated.
Code: Select all
#SingleInstance, Force
SetBatchlines, -1
Gui, Add, Button, y5 gSetPen, Pen
Gui, Add, Button, y5 gSetSelect, Select
Gui, Add, Button, y5 gSetErase, Erase
Gui, Add, Button, y5 gSetThin, Thin
Gui, Add, Button, y5 gSetWide, Wide
Gui, Add, Button, y5 gSetOpaque, Opaque
Gui, Add, Button, y5 gSetTransparent, Transparent
Gui, Add, Button, y5 gPressure_On, Pressure On
Gui, Add, Button, y5 gPressure_Off, Pressure Off
Gui Add, ActiveX, xm w600 h100 vBox, msinkaut.InkPicture.1
;Box.AutoRedraw := true ;not necessary, but setting to false = ink disappears when gui is minimized
Box.DefaultDrawingAttributes.Width := 100
;;;;;;;;;;;;;;;;;;;;;;; THESE TWO LINES DON'T WORK
;Box.DefaultDrawingAttributes.Color := Color.Red
;Box.Cursor := System.Windows.Forms.Cursors.Cross
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Gui, Show, AutoSize
Return
SetPen:
Box.EditingMode := 0
Return
SetSelect:
Box.EditingMode := 2
Return
SetErase:
Box.EditingMode := 1
Return
SetThin:
Box.DefaultDrawingAttributes.Width := 100
Return
SetWide:
Box.DefaultDrawingAttributes.Width := 300
Return
SetOpaque:
Box.DefaultDrawingAttributes.Transparency := 0
Return
SetTransparent:
Box.DefaultDrawingAttributes.Transparency := 200
Return
Pressure_On:
Box.DefaultDrawingAttributes.IgnorePressure := false
Return
Pressure_Off:
Box.DefaultDrawingAttributes.IgnorePressure := true
Return
GuiClose:
ExitApp
F7::
Reload
[Solved] COM INK control issues. KeyUp, KeyDown and KeyPress
Posted: 11 Oct 2013, 15:29
by tidbit
Been at this for a few hours now, no idea what is going on.
My goal: detect when a user presses a key, like enter (0x0D) and then do stuff. I could simply use Enter:: inside and #if, but thats cheating. I want to know why these built-in events are not working.
KeyUp() and KeyDown() don't even work. KeyPress() detects keys but it's not returning (from what I can tell) the key code that's pressed.
http://msdn.microsoft.com/en-us/library ... s.85).aspxCode: Select all
#SingleInstance force
Gui, +hwndMYGUI
;Gui, font, s16
;Gui Add, Text,, Draw in the picture box below`nPress E to toggle erasing.`nSwitching to erase mode also smooths the strokes.
;Gui Add, ActiveX, xm w600 h300 vss, msinkaut.InkPicture.1
Gui Add, Text,, Use handwriting recognition below (write letters and wait a bit)
Gui Add, ActiveX, xm w600 h100 vink, InkEd.InkEdit.1
ComObjConnect(ink, ink_events)
ink.UseMouseForInput := 1
ink.InkInsertMode := 0
ink.Font.Size:=24
ss.backColor:=0x000000
ss.DefaultDrawingAttributes.Color:=0xffffff
ss.DefaultDrawingAttributes.FitToCurve:=1
Gui, Show
Return
#if (WinActive("AHK_ID " MYGUI))
e::
if (ss.CollectingInk=0)
{
toggle:=!toggle
ss.EditingMode:=toggle
}
return
^j::
value:=ink.text
msgbox %value%
return
#if
; docs are here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms695538(v=vs.85).aspx
class ink_events
{
KeyPress(g) ; broken
{
tooltip, % "1::" g
}
KeyUp(g) ; broken
{
tooltip, % "2::" g
}
KeyDown(g) ; broken
{
tooltip, % "3::" g
}
Click() ; works
{
ToolTip, works
}
}
GuiClose:
esc::
ExitApp
return
Re: Drawing & Handwriting Objects. Great for touchscreen dev
Posted: 11 Oct 2013, 16:01
by lblb
Thanks to tidbit (
http://auto-hotkey.com/boards/viewtopic.php?f=5&t=233), I now know that the color of the ink can be changed if you use the hex code. For example:
Box.DefaultDrawingAttributes.Color:=0x99FF33
So thanks tidbit. I still don't know what to do with the cursor though and I'd be happy to hear if anyone has suggestions. And if anyone could direct me to a resource that would help me understand some of the basic syntax stuff like I mentioned in my previous post it would be greatly appreciated.
Re: COM INK control issues. KeyUp, KeyDown and KeyPress
Posted: 11 Oct 2013, 16:42
by Zelio
I already had problem with key and COM did you tried an "TranslateAccelerator" ? here my old ask for help
http://www.autohotkey.com/board/topic/7 ... m-browser/
Re: COM INK control issues. KeyUp, KeyDown and KeyPress
Posted: 11 Oct 2013, 19:02
by jethrow
I haven't seen anyone else use the
InkEd Control with AHK yet, so you are providing the ground-breaking code. That being said, the keypress event is working fine - you're just not understanding the parameters. I might recommend setting up an event listener:
Code: Select all
ComObjConnect(ink, new ink_events)
class ink_events {
__Call(event, p*) {
if (event != "mousemove") {
; event is the event name
; p is an array with all the parameters
}
}
}
Note that you will be triggering a lot of events - so you may want to output to gui or notepad. Also note that I excluded mousemove.
Re: Drawing & Handwriting Objects. Great for touchscreen dev
Posted: 11 Oct 2013, 19:24
by PointCloud
I ran this with a Wacom Bamboo tablet and it picks up the pen sensitivity. The one thing I did notice is the drivers for the MS/Wacom recongnized kick on in the handwriting box. I believe it is the Tablet PC Input Panel. The popup can be disabled through it's options. Thanks for this.
Cheers!
Re: COM INK control issues. KeyUp, KeyDown and KeyPress
Posted: 12 Oct 2013, 10:09
by tidbit
Thank you,
jethrow. This is also from TLM
I just tried to adapt it for my script and this was the only issue. Something that should be simple x__x
This is what I got now, but apparently the Press event isn't showing any keys (or any kind of output)
Code: Select all
#SingleInstance force
Gui, +hwndMYGUI
;Gui, font, s16
;Gui Add, Text,, Draw in the picture box below`nPress E to toggle erasing.`nSwitching to erase mode also smooths the strokes.
;Gui Add, ActiveX, xm w600 h300 vss, msinkaut.InkPicture.1
Gui Add, Text,, Use handwriting recognition below (write letters and wait a bit)
Gui, add, edit, xm w600 r15 vdebug
Gui Add, ActiveX, xm w600 h100 vink, InkEd.InkEdit.1
ComObjConnect(ink, new ink_events)
ink.UseMouseForInput := 1
ink.InkInsertMode := 0
ink.Font.Size:=24
ss.backColor:=0x000000
ss.DefaultDrawingAttributes.Color:=0xffffff
ss.DefaultDrawingAttributes.FitToCurve:=1
Gui, Show
Return
#if (WinActive("AHK_ID " MYGUI))
e::
if (ss.CollectingInk=0)
{
toggle:=!toggle
ss.EditingMode:=toggle
}
return
^j::
value:=ink.text
msgbox %value%
return
#if
class ink_events
{
__Call(event, p*)
{
if (event != "mousemove")
{
GuiControlGet, debug
p1:=p[1],p2:=p[2],p3:=p[3],p4:=p[4]
GuiControl,, debug, %event%1: %p1%`t2: %p2%`t3: %p3%`t4: %p4%`n%debug%
}
}
}
Zelio:
I'm not really sure if that'd fix my problem, also seems like quite the workaround.
Guess I'll do what I don't want to do.
#if (....) enter:: #if
Re: Drawing & Handwriting Objects. Great for touchscreen dev
Posted: 12 Oct 2013, 20:02
by PuzzledGreatly
Thanks for the link and the example. I couldn't make the character recognition work which I would very much like to do. Could that be because I have a bamboo pen and touch and it is over-riding the AHK code?
Re: COM INK control issues. KeyUp, KeyDown and KeyPress
Posted: 12 Oct 2013, 23:05
by jethrow
Code: Select all
KeyPress(g*) ; not-broken :-)
{
tooltip, % "1::" StrGet(ComObjValue(g[1]))
}
Re: COM INK control issues. KeyUp, KeyDown and KeyPress
Posted: 13 Oct 2013, 09:28
by tidbit
That works perfectly, thanks a ton!
tooltip, % "1::" asc(StrGet(ComObjValue(g[1])))
Re: COM INK control issues. KeyUp, KeyDown and KeyPress
Posted: 13 Oct 2013, 09:43
by TLM
Nice work Jethrow
So it was a pointer based array after all.
I was very close to this..
Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP
Posted: 13 Oct 2013, 13:42
by jethrow
In case you're typing a password:
Code: Select all
KeyPress(g*)
{
if ASC(StrGet(ComObjValue(g.1))) != 8
StrPut("*", (ComObjValue(g.1)))
}
Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP
Posted: 13 Oct 2013, 18:24
by TLM
tidbit I got the MouseUp() event and smooth application working.
Its so fast that I had to put sleep in front of it..
Code: Select all
Global ss
Gui, +hwndMYGUI
Gui Add, Text,, Draw in the picture box below`nPress E to toggle erasing.`nSwitching to erase mode also smooths the strokes.
Gui Add, ActiveX, xm w600 h300 vss, msinkaut.InkPicture.1
ComObjConnect(ss, new ink_events)
ss.backColor:=0x0
ss.DefaultDrawingAttributes.Color:=0xffff
ss.DefaultDrawingAttributes.FitToCurve:=1
Gui, Show
Return
#if (WinActive("AHK_ID " MYGUI))
e::ss.EditingMode:=!ss.CollectingInk?(t:=!t):
#if
class ink_events
{
MouseUp() {
sleep, 10
Loop 2
ss.EditingMode:=(i:=!i)
}
}
There must be built function for smoothing.
Also I'm half alseep cause I forgot how to pass the object to class
Used Global, Object ... zzzzzz
Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP
Posted: 13 Oct 2013, 18:35
by lblb
Hi TLM,
I'm not sure that's what you mean but if you are talking about smoothing of the ink strokes, I think it's because by default Antialiasing is set to true. Switch to false and it won't be smoothed:
ss.DefaultDrawingAttributes.Antialiased:=False
Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP
Posted: 13 Oct 2013, 19:35
by tidbit
lblb
we want it to be smoothed (AA + on curve) automatically after done drawing. Just like when you go into Erase mode on my above examples, but instead it should smooth when done drawing (mouseUp() event).
TLM's works, but it's kind of the brute-force (but still short and easy) method of doing it.
Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP
Posted: 13 Oct 2013, 20:19
by TLM
The correct property is AutoRedraw
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Code: Select all
Global ss
Gui, +hwndMYGUI
Gui Add, Text,, Draw in the picture box below`nPress E to toggle erasing.`nSwitching to erase mode also smooths the strokes.
Gui Add, ActiveX, xm w600 h300 vss, msinkaut.InkPicture.1
ComObjConnect(ss, new ink_events)
ss.backColor:=0x0
ss.DefaultDrawingAttributes.Color:=0xffff
ss.DefaultDrawingAttributes.FitToCurve:=1
Gui, Show
Return
#if (WinActive("AHK_ID " MYGUI))
e::ss.EditingMode:=!ss.CollectingInk?(t:=!t):
#if
class ink_events
{
MouseUp() {
ss.AutoRedraw:=1
}
}
A value of 0 clears and repaints the ink control. Interestingly enough the msdn docs refer to WM_Paint.
I saw this when I was spying the control messages.
Perhaps this is a way to get a better idea of what features are present.
tidbit maybe you should rename/move or merge this thread with my original one.
I like the way its going. Next up, Editing
Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP
Posted: 13 Oct 2013, 22:56
by TLM
Code: Select all
Global ss
Gui, +hwndMYGUI
Gui Add, Text,, % "Draw in the picture box below`n"
. "Press D to toggle erasing. [ C toggles spot/stroke erase ]`n"
. "Press E to toggle Edit Mode.`n"
. "In Edit Mode you can scale, move, copy and paste strokes.`n"
. "H Docks the control to the program manager [ experimental ]"
Gui Add, ActiveX, xm w600 h300 vss, msinkaut.InkPicture.1
ComObjConnect(ss, new ink_events)
ss.backColor:=0x0
ss.DefaultDrawingAttributes.Color:=0xffff
ss.DefaultDrawingAttributes.FitToCurve:=1
Gui, Show
Return
#if (WinActive("AHK_ID " MYGUI))
d::ss.EditingMode:=!ss.CollectingInk?(t:=!t):
e::ss.EditingMode:=(e:=!e)?2:1
c::ss.EraserMode:=(c:=!c)?0:1
h:: ; experimental 1 way dock
GuiControl, Move, ss, % "w" a_screenwidth " h" a_screenheight
DllCall("SetParent", uInt, ss.hwnd, uInt, WinExist("ahk_class Progman"))
WinMinimize % "ahk_id " MYGUI
Return
#if
class ink_events
{
MouseUp() {
ss.AutoRedraw:=1
}
}
GuiClose:
ExitApp
Added a few more features, mostly for experimentation
Re: Drawing & Handwriting Objects. Great for touchscreen dev
Posted: 12 Nov 2013, 17:05
by Flow Snake
Very cool TLM
but do you know how i get the Font to be random colors?
(ink.SelColor := %RandomX%)
instead of this (ink.SelColor := 1042040)
Code: Select all
Random,colorX,1000000,1400000
Gui Add, ActiveX, xm w600 h100 vink, InkEd.InkEdit.1
(ink.UseMouseForInput := 1), (ink.InkInsertMode := 0)
(ink.BackColor := 225)
(ink.SelFontName := "Small Fonts")
(ink.SelFontSize := 28)
(ink.SelColor := %RandomX%)
Gui +Resize
Gui Show
Return
MButton::
Reload