Does it work?
Published on July 21, 2005 By MountainDragon In DesktopX
Has anyone had success using the Object.RegisterHotkey method? If so, could you post an example snippet? I can't seem to get it to work.
Comments (Page 1)
2 Pages1 2 
on Jul 21, 2005
It's not Object_RegisterHotkey, it's Object.RegisterHotkey. Then use the subroutine Sub Object_OnHotkey(id) to catch the hotkeys.
on Jul 21, 2005
Thomas - Yeah, I know - I did use Object.RegisterHotkey in the code. Have you gotten it to work, then?
on Jul 21, 2005
hmm... nope... not really. I don't unserstand how the hotkeyValue is suppose to be formatted. I tried Object.RegisterHotkey 1, &H46 And &H00000002, &H46 beeing the hex virtual code for F and &H00000002 beeing the Control modifier. But it doesn't work. I don't get it. I get the feeling that the documents assume some C knowledge...
on Jul 21, 2005
loworder-byte, highorder-byte. HIWORD, LOWORD. ... ? All to confusing.

I did a search and I came across this site: http://www.freevbcode.com/ShowCode.asp?ID=2650

I adapted the code to go into VBScript:

Const hKeyShift = &H00000001
Const hKeyControl = &H00000002
Const hKeyAlt = &H00000004
Const hKeyExtended = &H00000008
Const hKeyF = &H46

'Called when the script is executed
Sub Object_OnScriptEnter
Object.RegisterHotkey 1, MakeLong(hKeyF, hKeyControl)
Script.MsgBox "HotkeyStart"
End Sub

'Called when the script is terminated
Sub Object_OnScriptExit
Object.UnregisterHotkey 1
End Sub

Sub Object_OnHotkey(id)
Script.MsgBox "Hello World!" & vbCrLf & id
End Sub

Public Function MakeLong(ByVal LoWord, ByVal HiWord)
MakeLong = ((HiWord * &H10000) + LoWord)
End Function



But with not results... I'll try to grab hold of someone on IRC tomorrow.
on Jul 21, 2005
I get the feeling that the documents assume some C knowledge...


The thing is, I do have C knowledge (20 years )

As near as I get from the doc that Alberto (or whomever) wrote, it's a WORD argument (2 bytes) with the flag in the hi-order byte and the key value in the lo-order byte.

So, you should be able to just send &H0431 (for Alt-1) or whatever. But this did not work as expected.

I did notice that the object would seem to fail on it's initialization depending on what I sent to the function. I only noticed this because it's supposed to position itself on script entry, and sometimes it didn't.

Alberto, are you there?
on Jul 22, 2005
I tried to see if it only worked if the object where complied as a widget, but I got no result there either.

When I try your &H0431 nothing seem to excecute after that.
on Jul 22, 2005
When I try your &H0431 nothing seem to excecute after that.



Yeah, same result here. Very strange. I asked Green Reaper about it and he hadn't tried it, so I emailed tech support and have yet to hear back.
on Jul 23, 2005
Will you post back here when you hear from them. This has made me curious. It'll be my weekend mystery.
on Jul 25, 2005
Well, I'm stuck. Have you managed to work something out?
on Jul 25, 2005
Thomas - I've sent two emails, and heard nothing back. I suspect, with the number of errors I'm seeing accessing the site, that they are a bit busy. That shouldn't involve Alberto, though, should it?
on Jul 26, 2005
hmm... Dunno if Alberto do siterepairs. I haven't seen him on IRC until today just he disappeared before I could ask him.
on Jul 27, 2005
I just got an example of how to use RegisterHotkey. Not sure if it's what you are looking for.


Sub Object_OnScriptEnter
Widget.AddPreference("hotkey")
Widget.preference("hotkey").Type = "hotkey"
Widget.preference("hotkey").caption = "ZOrder hotkey"
Widget.preference("hotkey").description = "You can use this hotkey to trigger the RSS Reader on top of all other windows"
SetHotkey
End Sub

Sub Widget_OnPreferencesChange
SetHotkey
End Sub

Sub SetHotkey
Object.RegisterHotkey 1, Widget.Preference("hotkey").Value
End Sub

Sub Object_OnHotkey(id)
Widget.OnTop
End Sub


I asked him for an example of a hardcoded hotkey as I can imagine I might have use for it.
on Jul 27, 2005
Thomas - based on the example, but modified because I want to use it in a theme, not a widget, this is what I tried, and the hotkey still does not seem to function:

'Called when the script is executed
Sub Object_OnScriptEnter

End Sub

'Called when the script is terminated
Sub Object_OnScriptExit
Object.UnregisterHotkey(1)
End Sub

Dim h

Sub Object_OnLButtonUp(x,y,dragged)
If Not dragged Then
Set form=Desktopx.CreateForm
form.AddPreference("Hotkey")
form.Preference("Hotkey").Type="hotkey"
form.Preference("Hotkey").Caption="Hotkey:"
form.Preference("Hotkey").Value=h
If( form.Prompt ) Then
h=form.Preference("Hotkey").Value
MsgBox("Setting hotkey")
Object.RegisterHotkey 1,h
End If
End If
End Sub

Sub Object_OnHotkey(id)
MsgBox("Hit")
End Sub




Who did you talk to? I guess tech support must be out to lunch on this one.
on Jul 27, 2005
I got hold of Alberto on IRC. He showed me a sneakpeak of the Neowin gadget sourcecode. I addapted it to the code I posted. It worked as an widget to me.

I could get your code to work if I replaced Object.RegisterHotkey 1,h with Object.RegisterHotkey 1, form.Preference("Hotkey").Value

I have no idea why that should matter.
on Jul 27, 2005
Could it be... because the value is stored in this hiword and loword that the bits get misinterpreted when converted into a variable then back again to the RegisterHotkey?
2 Pages1 2