Drawing & Handwriting Objects. Great for touchscreen devices

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Drawing & Handwriting Objects. Great for touchscreen devices

10 Oct 2013, 18:24

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.
User avatar
Learning one
Posts: 173
Joined: 04 Oct 2013, 13:59
Location: Croatia
Contact:

Re: Drawing & Handwriting Objects. Great for touchscreen dev

11 Oct 2013, 02:21

Very nice TLM! Thanks for sharing! :)
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: Drawing & Handwriting Objects. Great for touchscreen dev

11 Oct 2013, 03:10

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
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

[Solved] COM INK control issues. KeyUp, KeyDown and KeyPress

11 Oct 2013, 15:29

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).aspx

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, 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
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: Drawing & Handwriting Objects. Great for touchscreen dev

11 Oct 2013, 16:01

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.
Zelio
Posts: 278
Joined: 30 Sep 2013, 00:45
Location: France

Re: COM INK control issues. KeyUp, KeyDown and KeyPress

11 Oct 2013, 16:42

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/
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM INK control issues. KeyUp, KeyDown and KeyPress

11 Oct 2013, 19:02

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.
User avatar
PointCloud
Posts: 26
Joined: 30 Sep 2013, 07:24
Location: U.S.A.

Re: Drawing & Handwriting Objects. Great for touchscreen dev

11 Oct 2013, 19:24

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!
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: COM INK control issues. KeyUp, KeyDown and KeyPress

12 Oct 2013, 10:09

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
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Drawing & Handwriting Objects. Great for touchscreen dev

12 Oct 2013, 20:02

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?
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM INK control issues. KeyUp, KeyDown and KeyPress

12 Oct 2013, 23:05

Code: Select all

   KeyPress(g*) ; not-broken :-)
   {
      tooltip, % "1::" StrGet(ComObjValue(g[1]))
   }
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: COM INK control issues. KeyUp, KeyDown and KeyPress

13 Oct 2013, 09:28

That works perfectly, thanks a ton!
tooltip, % "1::" asc(StrGet(ComObjValue(g[1])))
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: COM INK control issues. KeyUp, KeyDown and KeyPress

13 Oct 2013, 09:43

Nice work Jethrow :D
So it was a pointer based array after all.
I was very close to this..
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP

13 Oct 2013, 13:42

In case you're typing a password:

Code: Select all

KeyPress(g*)
{
	if ASC(StrGet(ComObjValue(g.1))) != 8
		StrPut("*", (ComObjValue(g.1)))
}
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP

13 Oct 2013, 18:24

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
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP

13 Oct 2013, 18:35

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
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP

13 Oct 2013, 19:35

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.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP

13 Oct 2013, 20:19

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 :D
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: [Solved] COM INK control issues. KeyUp, KeyDown and KeyP

13 Oct 2013, 22:56

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
Flow Snake
Posts: 11
Joined: 29 Sep 2013, 16:48
Location: The Kindom Of Sweden

Re: Drawing & Handwriting Objects. Great for touchscreen dev

12 Nov 2013, 17:05

Very cool TLM :D 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
Image

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 136 guests