Object.RegisterHotkey

Does it work?

Thursday, July 21, 2005 by MountainDragon | Discussion: 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.
thomassen
Reply #1 Thursday, July 21, 2005 1:53 PM
It's not Object_RegisterHotkey, it's Object.RegisterHotkey. Then use the subroutine Sub Object_OnHotkey(id) to catch the hotkeys.
MountainDragon
Reply #2 Thursday, July 21, 2005 2:13 PM
Thomas - Yeah, I know - I did use Object.RegisterHotkey in the code. Have you gotten it to work, then?
thomassen
Reply #3 Thursday, July 21, 2005 3:47 PM
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...
thomassen
Reply #4 Thursday, July 21, 2005 3:56 PM
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.
MountainDragon
Reply #5 Thursday, July 21, 2005 5:31 PM
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?
thomassen
Reply #6 Friday, July 22, 2005 2:18 PM
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.
MountainDragon
Reply #7 Friday, July 22, 2005 4:59 PM
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.
thomassen
Reply #8 Saturday, July 23, 2005 9:46 AM
Will you post back here when you hear from them. This has made me curious. It'll be my weekend mystery.
thomassen
Reply #9 Monday, July 25, 2005 3:27 PM
Well, I'm stuck. Have you managed to work something out?
MountainDragon
Reply #10 Monday, July 25, 2005 3:46 PM
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?
thomassen
Reply #11 Tuesday, July 26, 2005 12:23 PM
hmm... Dunno if Alberto do siterepairs. I haven't seen him on IRC until today just he disappeared before I could ask him.
thomassen
Reply #12 Wednesday, July 27, 2005 1:03 PM
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.
MountainDragon
Reply #13 Wednesday, July 27, 2005 1:56 PM
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.
thomassen
Reply #14 Wednesday, July 27, 2005 3:11 PM
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.
thomassen
Reply #15 Wednesday, July 27, 2005 3:50 PM
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?
MountainDragon
Reply #16 Wednesday, July 27, 2005 3:57 PM
Maybe that's it. Thanks for exploring this with me.

Posted via WinCustomize Browser/Stardock Central

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01