FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister   ProfileProfile    Log inLog in   RSS Feed

system keys; space bar, left, right etc.

 
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Mac
View previous topic :: View next topic  
Author Message
Wolfmother
Newbie


Joined: 24 Mar 2006
Posts: 4

PostPosted: Fri Mar 24, 2006 10:00 am    Post subject: system keys; space bar, left, right etc. Reply with quote

Can anyone tell me if it is possible to emulate hitting a key on the keyboard?

I like the way one can move the mouse with the Salling clicker - and I've used it to interact with a flash movie, but it could be just as easy to use key presses as the trigger for a lot of interaction, so I made a small flash movie that will react to keyboard presses, but now have no idea how to script them (or even if it's possible).
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Fri Mar 24, 2006 12:34 pm    Post subject: Re: system keys; space bar, left, right etc. Reply with quote

Hi,

This is certainly possible. This should give you some ideas:

http://www.salling.com/forums/viewtopic.php?t=3031

Best.
--
Jonas

[quote="Wolfmother"]Can anyone tell me if it is possible to emulate hitting a key on the keyboard?

I like the way one can move the mouse with the Salling clicker - and I've used it to interact with a flash movie, but it could be just as easy to use key presses as the trigger for a lot of interaction, so I made a small flash movie that will react to keyboard presses, but now have no idea how to script them (or even if it's possible).[/quote]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Wolfmother
Newbie


Joined: 24 Mar 2006
Posts: 4

PostPosted: Fri Mar 24, 2006 2:17 pm    Post subject: Reply with quote

Okay its great to hear it's possible, however i'm embaressed to say that I'm a complete beginner with programming, but i'm very keen to learn (I'm doing some applesrcipt tutorials as I write this). I can see that VK_CODE is a function that must be declared as a property in the headers, is that correct? But other than that I'm lost. Would it be possible to see a complete script for the keydown?... If I can see that then I'll know how to write the rest myself...Hope that's not too much to ask, W.

tell application "SEC Helper" to simulate keyboard virtual down keycode VK_CODE
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Fri Mar 24, 2006 2:26 pm    Post subject: Reply with quote

That's okay.

Btw: There are no "headers" in AppleScript. For VK_CODE, insert a numerical value representing the key you want to have pressed. Here's a table:

http://www.salling.com/forums/viewtopic.php?t=1619

Best.
--
Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Wolfmother
Newbie


Joined: 24 Mar 2006
Posts: 4

PostPosted: Sat Mar 25, 2006 8:56 am    Post subject: almost there Reply with quote

okay so, I learnt applescript today, but its been a long day! So, using the key codes you sent me I hacked together the follwing script, but it isn't working- can anyone tell me why- I'm getting a bit fatigued!

on key_was_depressed(keyCode)
try
tell application "SEC Helper"
if keyCode is "<" or keyCode is "4" then
tell application "SEC Helper" to simulate keyboard virtual keycode 123
else if keyCode is ">" or keyCode is "6" then
tell application "SEC Helper" to simulate keyboard virtual keycode 124
else if keyCode is "^" or keyCode is "2" then
tell application "SEC Helper" to simulate keyboard virtual keycode 126
else if keyCode is "v" or keyCode is "8" then
tell application "SEC Helper" to simulate keyboard virtual keycode 125

end if
end tell
end try
end key_was_depressed :?
Back to top
View user's profile Send private message
GIRO
Newbie


Joined: 26 Mar 2006
Posts: 1

PostPosted: Sun Mar 26, 2006 5:35 pm    Post subject: virtual key, keyboard layouts and localization Reply with quote

Hi everybody,
Here is my little contribution to help scripters to solve their problems with the utilisation of virtual key.
Unfortunately the keycode seems to change in function of the localization of your keyboard.
i.e I had a lot of problems when i tried to use the map provided by jonas here :
[url]http://www.salling.com/forums/viewtopic.php?t=1619[/url]

Some of the keys provided were not functionnal :cry: :
#define kMinusKey 0x1B
#define kEqualsKey 0x18

The code I used seemed pretty clean and it was fuctional in the case of a reattribution of an existing and working keycode (123 and 124).

I guess the reason is that my usual keyboard layout is french.

on a french keyboard layout
minusKey is 0x18
equalkey is 0x2c

In Decimal it's "-" 24 and "=" 44

Now, for the beginners, when you're looking for the decimal value of a "0x18" you can ask Google for "0x18 in decimal" it'll give you the answer you need (ie 24).

If you need to determine or check the key code of a shortcut, there's a marvellous utility made by Peter Maurer (Thanx Peter you made my life easier :) ).
It's name is evocative "Key Codes 1.0.1". It's free and here is the link to download it : [quote][url=http://www.petermaurer.de/nasi.php?section=keycodes&layout=default]This is just a little utility that displays the key code and modifier keys state for any key combination you press. Some fellow developers have asked me to make this publicly available, so here you are...[/url][/quote]

With this utilitity I added functionalities and customized my VLC Controler for a french layout without problem.
Hope this will help.
GIRO
Back to top
View user's profile Send private message
Wolfmother
Newbie


Joined: 24 Mar 2006
Posts: 4

PostPosted: Mon Mar 27, 2006 4:01 am    Post subject: Reply with quote

Thanks Giro for posting that link and thanks to Peter Maurer for writing the Key Code app; I've already found it useful. Anyway, the following is my space bar, up down left right keyboard emulator. I works fine.

using terms from application "SEC Helper"

tell application "SEC Helper"
enter keypad mode text return & "CocoaAppName" & return & "Navigator" & return & return & "Use Joystick" & return & "or Keypad" key repeated "keyHeldDown" key depressed "keyPressedOnce"
end tell

on keyHeldDown(keyCode)
if keyCode is "<" or keyCode is "4" then
tell application "SEC Helper" to simulate keyboard virtual keycode 123
else if keyCode is ">" or keyCode is "6" then
tell application "SEC Helper" to simulate keyboard virtual keycode 124
else if keyCode is "^" or keyCode is "2" then
tell application "SEC Helper" to simulate keyboard virtual keycode 126
else if keyCode is "v" or keyCode is "5" then
tell application "SEC Helper" to simulate keyboard virtual keycode 125
else if keyCode is "*" then
tell application "SEC Helper" to simulate keyboard special key volume down
else if keyCode is "#" then
tell application "SEC Helper" to simulate keyboard special key volume up
end if
end keyHeldDown

on keyPressedOnce(keyCode)
if keyCode is "<" or keyCode is "4" then
tell application "SEC Helper" to simulate keyboard virtual keycode 123
else if keyCode is ">" or keyCode is "6" then
tell application "SEC Helper" to simulate keyboard virtual keycode 124
else if keyCode is "^" or keyCode is "2" then
tell application "SEC Helper" to simulate keyboard virtual keycode 126
else if keyCode is "v" or keyCode is "5" then
tell application "SEC Helper" to simulate keyboard virtual keycode 125
else if keyCode is "s" then
tell application "SEC Helper" to simulate keyboard virtual keycode 49
else if keyCode is "8" then
tell application "SEC Helper" to simulate keyboard virtual keycode 49
else if keyCode is "c" then
tell application "SEC Helper" to simulate keyboard virtual keycode 53
else if keyCode is "#" then
tell application "myCocoaApp"
quit
end tell
else if keyCode is "0" then
tell application "myCocoaApp"
launch
end tell
else if keyCode is "*" then
tell application "SEC Helper" to simulate keyboard special key volume down
else if keyCode is "7" then
tell application "SEC Helper" to simulate keyboard special key volume up
end if
end keyPressedOnce

end using terms from
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Mac All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group